Skip to content

Instantly share code, notes, and snippets.

@OlaoluwaM
Last active October 7, 2020 23:48
Show Gist options
  • Save OlaoluwaM/b08e110b3ff3de8dd61467583206b6e3 to your computer and use it in GitHub Desktop.
Save OlaoluwaM/b08e110b3ff3de8dd61467583206b6e3 to your computer and use it in GitHub Desktop.
React Toastify test snippet example
jest.useFakeTimers()
test('should inform user of task completion', () => {
const { getByRole } = render(<App />)
jest.advanceTimersByTime(1000); // You can vary the time depending on how long you have set the toast in question to be visible for
const toast = getByRole('alert') // Toasts generated by the library have a role of alert
expect(toast).toBeInTheDocument();
})
// You can also do it like so
test('should inform user of task completion', () => {
const { getByRole } = render(<App />)
act(() => {
jest.advanceTimersByTime(1000);
})
const toast = getByRole('alert')
expect(toast).toBeInTheDocument();
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment