Skip to content

Instantly share code, notes, and snippets.

@dilantha111
Created August 24, 2020 17:39
Show Gist options
  • Save dilantha111/a5448f12132e9736983f227685985a51 to your computer and use it in GitHub Desktop.
Save dilantha111/a5448f12132e9736983f227685985a51 to your computer and use it in GitHub Desktop.
import React from 'react';
import { shallow, mount, render, act } from 'enzyme';
import { getMetalGenres } from './services/music-genres';
import App from './App';
jest.mock('./services/music-genres');
describe("App component", () => {
const genreList = [
"Gothic Metal",
"Thrash Metal",
"Heavy Metal"
];
beforeEach(() => {
getMetalGenres.mockResolvedValue(genreList);
});
afterEach(() => {
jest.resetAllMocks();
});
it('should render without throwing an error', () => {
expect(shallow(<App />).contains(<h1> Metal Music Genres </h1>)).toBe(true);
});
it('calls the getMetalGenres properly', async () => {
const wrapper = mount(<App/>);
wrapper.find('.btn-container button').simulate('click');
expect(getMetalGenres).toHaveBeenCalledTimes(1);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment