-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Expand file tree
/
Copy pathnotificationProvider.test.jsx
More file actions
43 lines (36 loc) · 1.16 KB
/
notificationProvider.test.jsx
File metadata and controls
43 lines (36 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { describe, it } from 'node:test';
import assert from 'node:assert/strict';
import { render, act, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import {
NotificationProvider,
NotificationDispatch,
} from '#site/providers/notificationProvider';
describe('NotificationProvider', () => {
it('renders children and shows notification with the provided message', async t => {
t.mock.timers.enable();
const testMessage = 'Test Notification';
const testDuration = 3000;
const { getByText } = render(
<NotificationProvider>
<NotificationDispatch.Consumer>
{dispatch => (
<button
onClick={() =>
dispatch({ message: testMessage, duration: testDuration })
}
>
Show Notification
</button>
)}
</NotificationDispatch.Consumer>
</NotificationProvider>
);
act(() => {
userEvent.click(getByText('Show Notification'));
t.mock.timers.tick(3000);
});
t.mock.timers.reset();
await waitFor(() => assert.ok(getByText(testMessage).ownerDocument));
});
});