-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Expand file tree
/
Copy pathNotificationProvider.test.jsx
More file actions
53 lines (44 loc) · 1.52 KB
/
NotificationProvider.test.jsx
File metadata and controls
53 lines (44 loc) · 1.52 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
44
45
46
47
48
49
50
51
52
53
import { render } from '@testing-library/react';
import { describe, it } from 'node:test';
import assert from 'node:assert/strict';
import { NotificationProvider, useNotification } from '../NotificationProvider';
describe('useNotification', () => {
it('should return the notification dispatch function', () => {
// Arrange
const TestComponent = () => {
const notificationDispatch = useNotification();
return (
<div>
{notificationDispatch ? 'Dispatch available' : 'Dispatch unavailable'}
</div>
);
};
// Act
const { getByText } = render(
<NotificationProvider>
<TestComponent />
</NotificationProvider>
);
// Assert
const result = getByText('Dispatch available');
assert.ok(result.ownerDocument);
});
it('should return null outside NotificationProvider', () => {
// Arrange
const TestComponent = () => {
const notificationDispatch = useNotification();
return (
<div>
{notificationDispatch ? 'Dispatch available' : 'Dispatch unavailable'}
</div>
);
};
// Act
const { queryByText } = render(<TestComponent />);
// Assert
const result = queryByText((content, element) => {
return element.textContent === 'Dispatch unavailable';
});
assert.equal(result, null);
});
});