Created
February 22, 2021 04:16
-
-
Save rohanBagchi/a9659f4d851c66edbc1102669611d780 to your computer and use it in GitHub Desktop.
devto-testing enzyme test
This file contains 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
import Enzyme from 'enzyme'; | |
import Adapter from '@wojtekmaj/enzyme-adapter-react-17'; | |
import { shallow } from 'enzyme'; | |
import App from './App'; | |
import axios from 'axios'; | |
Enzyme.configure({ adapter: new Adapter() }); | |
const joke = 'Foo Bar!'; | |
jest.mock('axios'); | |
test('App', async () => { | |
const wrapper = shallow(<App />); | |
const P = new Promise(resolve => resolve({ | |
data: { | |
type: "success", | |
value: { | |
joke | |
} | |
} | |
})); | |
axios.get = jest.fn().mockReturnValue(P); | |
wrapper | |
.find('button') | |
.simulate('click'); | |
await P; | |
expect(wrapper.find('h3').text()).toEqual(joke) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment