We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
import {act, render, screen} from '@testing-library/react' import {ReactNotifications, Store} from "react-notifications-component";
jest.useFakeTimers(); describe('notification types hide after 2 second', () => { test('should hide info', async () => { render() act(() => { Store.addNotification({ type: 'info', message: 'notification info', container: "bottom-right", dismiss: { duration: 2000 } }) }) const notificationBefore = await screen.findByText('notification info') expect(notificationBefore).toBeInTheDocument() act(() => { jest.advanceTimersByTime(3000) }) const notificationAfter = await screen.findByText('notification info') expect(notificationAfter).not.toBeInTheDocument() }) }) jest.clearAllTimers()
The notification is not removed from the DOM even if you try to apply the method Store.removeAllNotifications(). Maybe I'm doing something wrong?
The text was updated successfully, but these errors were encountered:
can you post a CodeSandbox example that illustrates this? I know testing async stuff with timers it's not the most straightforward thing in Jest.
I'm not sure how advanceTimersByTime work and if it's actually reliable to use those, where I work I use this
advanceTimersByTime
render(<Component />); await waitFor( () => { expect(loadUserMock).toHaveBeenCalled(); }, { timeout: 6000 } );
It seems you're not using waitFor.
waitFor
See if that helps maybe?
Sorry, something went wrong.
No branches or pull requests
import {act, render, screen} from '@testing-library/react'
import {ReactNotifications, Store} from "react-notifications-component";
jest.useFakeTimers();
describe('notification types hide after 2 second', () => {
test('should hide info',
async () => {
render()
act(() => {
Store.addNotification({
type: 'info', message: 'notification info',
container: "bottom-right", dismiss: {
duration: 2000
}
})
})
const notificationBefore = await screen.findByText('notification info')
expect(notificationBefore).toBeInTheDocument()
act(() => {
jest.advanceTimersByTime(3000)
})
const notificationAfter = await screen.findByText('notification info')
expect(notificationAfter).not.toBeInTheDocument()
})
})
jest.clearAllTimers()
The notification is not removed from the DOM even if you try to apply the method Store.removeAllNotifications(). Maybe I'm doing something wrong?
The text was updated successfully, but these errors were encountered: