Created
August 24, 2020 17:39
-
-
Save dilantha111/a5448f12132e9736983f227685985a51 to your computer and use it in GitHub Desktop.
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 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