Created
March 8, 2019 09:35
-
-
Save takethefake/065348c5281045e24772927a8ad97da6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// src/__mocks_axios.js | |
const mockAxios = jest.genMockFromModule('axios') | |
// this is the key to fix the axios.create() undefined error! | |
mockAxios.create = jest.fn(() => mockAxios) | |
export default mockAxios | |
// example test class which uses axios mock | |
import mockAxios from 'axios' | |
test('can add Todo to List', async () => { | |
mockAxios.get.mockImplementationOnce(() => | |
Promise.resolve({ | |
data: [], | |
}), | |
) | |
mockAxios.post.mockImplementationOnce(() => | |
Promise.resolve({ | |
data: [new Todo('test')], | |
}), | |
) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment