Skip to content

Instantly share code, notes, and snippets.

@mickaelw
Last active August 18, 2020 10:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mickaelw/5c96496469e5c76a01af7f09e8f1c6f4 to your computer and use it in GitHub Desktop.
Save mickaelw/5c96496469e5c76a01af7f09e8f1c6f4 to your computer and use it in GitHub Desktop.
describe('Integration | Component | Book information', () => {
let dependencies: Dependencies
beforeEach(() => {
dependencies = {
bookInformation: jest.fn().mockResolvedValue(null)
}
})
it('Matches to snapshot', async () => {
const { asFragment } = render(<BookInformation
bookTitle={ 'title' }
dependencies={ dependencies }/>
)
await waitFor(() => {
expect(asFragment()).toMatchSnapshot()
})
})
it('Fetch book information', async () => {
render(<BookInformation bookTitle={ 'title' } dependencies={ dependencies }/>)
await waitFor(() => {
expect(dependencies.bookInformation).toHaveBeenCalledTimes(1)
expect(dependencies.bookInformation).toHaveBeenCalledWith('title')
})
})
it('Refresh book information', async () => {
const { getByTestId } = render(<BookInformation
bookTitle={ 'title' }
dependencies={ dependencies }/>
)
fireEvent.click(getByTestId('refresh-button'))
await waitFor(() => {
expect(dependencies.bookInformation).toHaveBeenCalledTimes(2)
})
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment