Last active
October 7, 2020 23:48
-
-
Save OlaoluwaM/b08e110b3ff3de8dd61467583206b6e3 to your computer and use it in GitHub Desktop.
React Toastify test snippet example
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
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