Skip to content

Instantly share code, notes, and snippets.

@rohanBagchi
Created February 22, 2021 04:16
Show Gist options
  • Save rohanBagchi/a9659f4d851c66edbc1102669611d780 to your computer and use it in GitHub Desktop.
Save rohanBagchi/a9659f4d851c66edbc1102669611d780 to your computer and use it in GitHub Desktop.
devto-testing enzyme test
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