ant-design/components/notification/__tests__/util.ts
二货机器人 2341a25d91
feat: refactor useNotification (#35423)
* more refactor

* chore: motion support

* chore: tmp test

* test: Hooks

* chore: static function

* tmp of it

* all of it

* mv prefix

* chore: clean up

* chore: clean up

* more test case

* test: all base test

* test: all test case

* init

* refactor: rm notification.open instance related code

* follow up

* refactor: singlton

* test: notification test case

* refactor to destroy

* refactor: message base

* test: part test case

* test: more

* test: more

* test: all test

* chore: clean up

* docs: reorder

* chore: fix lint

* test: fix test case

* chore: add act

* chore: back

* chore: fix style

* test: notification test

* test: more and more

* test: fix more test

* test: index

* test: more & more

* test: fix placement

* test: fix coverage

* chore: clean up

* chore: bundle size

* fix: 17

* chore: more

* test: message

* test: more test

* fix: lint

* test: rm class in static

* chore: clean up

* test: coverage

* chore: fix lint
2022-05-11 14:26:18 +08:00

31 lines
754 B
TypeScript

import { act, fireEvent } from '../../../tests/utils';
export async function awaitPromise() {
for (let i = 0; i < 10; i += 1) {
// eslint-disable-next-line no-await-in-loop
await Promise.resolve();
}
}
export async function triggerMotionEnd(runAllTimers: boolean = true) {
await awaitPromise();
if (runAllTimers) {
// Flush css motion state update
for (let i = 0; i < 5; i += 1) {
act(() => {
jest.runAllTimers();
});
}
}
// document.querySelectorAll('.ant-notification-fade-leave').forEach(ele => {
// fireEvent.animationEnd(ele);
// });
document.querySelectorAll('[role="alert"]').forEach(ele => {
fireEvent.animationEnd(ele.parentNode?.parentNode!);
});
await awaitPromise();
}