ant-design/components/notification/__tests__/config.test.js
二货机器人 67ccf39bd3
fix: Notification & message throw createRoot warning in React 18 (#35030)
* chore: bump notification version

* test: notification test case

* test: more test case

* test: part message test

* test: rest message test

* test: notification config test
2022-04-14 18:09:19 +08:00

57 lines
1.2 KiB
JavaScript

import { act } from 'react-dom/test-utils';
import notification, { getInstance } from '..';
import { sleep } from '../../../tests/utils';
describe('notification.config', () => {
beforeEach(() => {
jest.useFakeTimers();
});
afterAll(() => {
notification.destroy();
});
it('should be able to config maxCount', async () => {
notification.config({
maxCount: 5,
duration: 0.5,
});
for (let i = 0; i < 10; i += 1) {
act(() => {
notification.open({
message: 'Notification message',
key: i,
});
});
}
act(() => {
notification.open({
message: 'Notification last',
key: '11',
});
});
await act(async () => {
await Promise.resolve();
});
expect(document.querySelectorAll('.ant-notification-notice').length).toBe(5);
expect(document.querySelectorAll('.ant-notification-notice')[4].textContent).toBe(
'Notification last',
);
act(() => {
jest.runAllTimers();
});
await act(async () => {
await sleep(500);
});
expect((await getInstance('ant-notification-topRight')).component.state.notices).toHaveLength(
0,
);
});
});