|
1 | | -import './AnimationEffect'; |
2 | | -import './KeyframeEffect'; |
3 | | -import './AnimationPlaybackEvent'; |
4 | | -import './DocumentTimeline'; |
| 1 | +import { mockKeyframeEffect } from './KeyframeEffect'; |
| 2 | +import { mockAnimationPlaybackEvent } from './AnimationPlaybackEvent'; |
| 3 | +import { mockDocumentTimeline } from './DocumentTimeline'; |
5 | 4 | import { getEasingFunctionFromString } from './easingFunctions'; |
6 | 5 |
|
7 | 6 | type ActiveAnimationTimeline = AnimationTimeline & { |
@@ -167,6 +166,11 @@ class MockedAnimation extends EventTarget implements Animation { |
167 | 166 | }); |
168 | 167 | } |
169 | 168 |
|
| 169 | + #silentlyRejectFinishedPromise(error: Error) { |
| 170 | + this.#finishedPromise.catch(noop); |
| 171 | + this.#resolvers.finished.reject(error); |
| 172 | + } |
| 173 | + |
170 | 174 | #hasPendingTask() { |
171 | 175 | return this.#pendingPauseTask || this.#pendingPlayTask; |
172 | 176 | } |
@@ -401,7 +405,9 @@ class MockedAnimation extends EventTarget implements Animation { |
401 | 405 | this.#applyPendingPlaybackRate(); |
402 | 406 |
|
403 | 407 | // 5. Reject animation’s current ready promise with a DOMException named "AbortError". |
404 | | - this.#resolvers.ready.reject(new DOMException('AbortError')); |
| 408 | + this.#silentlyRejectFinishedPromise( |
| 409 | + new DOMException(undefined, 'AbortError') |
| 410 | + ); |
405 | 411 |
|
406 | 412 | // 6. Set the [[PromiseIsHandled]] internal slot of animation’s current ready promise to true. |
407 | 413 |
|
@@ -1145,8 +1151,7 @@ class MockedAnimation extends EventTarget implements Animation { |
1145 | 1151 | this.#resetPendingTasks(); |
1146 | 1152 |
|
1147 | 1153 | // Reject the current finished promise with a DOMException named "AbortError". |
1148 | | - // this.#resolvers.finished.reject(new DOMException('AbortError')); |
1149 | | - this.#resolvers.finished.reject( |
| 1154 | + this.#silentlyRejectFinishedPromise( |
1150 | 1155 | new DOMException('The user aborted a request.', 'AbortError') |
1151 | 1156 | ); |
1152 | 1157 |
|
@@ -1688,12 +1693,18 @@ class MockedAnimation extends EventTarget implements Animation { |
1688 | 1693 | } |
1689 | 1694 | } |
1690 | 1695 |
|
1691 | | -if (typeof Animation === 'undefined') { |
1692 | | - Object.defineProperty(window, 'Animation', { |
1693 | | - writable: true, |
1694 | | - configurable: true, |
1695 | | - value: MockedAnimation, |
1696 | | - }); |
| 1696 | +function mockAnimation() { |
| 1697 | + mockKeyframeEffect(); |
| 1698 | + mockAnimationPlaybackEvent(); |
| 1699 | + mockDocumentTimeline(); |
| 1700 | + |
| 1701 | + if (typeof Animation === 'undefined') { |
| 1702 | + Object.defineProperty(window, 'Animation', { |
| 1703 | + writable: true, |
| 1704 | + configurable: true, |
| 1705 | + value: MockedAnimation, |
| 1706 | + }); |
| 1707 | + } |
1697 | 1708 | } |
1698 | 1709 |
|
1699 | | -export { MockedAnimation }; |
| 1710 | +export { MockedAnimation, mockAnimation }; |
0 commit comments