1 |
rakinar2 |
575 |
import { PromiseWithResolversReturn, promiseWithResolvers } from "@framework/polyfills/Promise"; |
2 |
|
|
import { describe, expect, it } from "vitest"; |
3 |
|
|
|
4 |
|
|
declare global { |
5 |
|
|
interface PromiseConstructor { |
6 |
rakinar2 |
632 |
// @ts-ignore |
7 |
rakinar2 |
575 |
withResolvers?<T>(): PromiseWithResolversReturn<T>; |
8 |
|
|
} |
9 |
|
|
} |
10 |
|
|
|
11 |
|
|
describe("Promise polyfill", () => { |
12 |
|
|
it("should polyfill Promise.withResolvers", async () => { |
13 |
|
|
// Arrange |
14 |
|
|
const originalPromise = Promise; |
15 |
|
|
|
16 |
|
|
// Act |
17 |
|
|
delete Promise.withResolvers; |
18 |
|
|
const { promise, resolve, reject } = promiseWithResolvers<void>(); |
19 |
|
|
|
20 |
|
|
// Assert |
21 |
|
|
expect(promise).toBeInstanceOf(originalPromise); |
22 |
|
|
expect(resolve).toBeInstanceOf(Function); |
23 |
|
|
expect(reject).toBeInstanceOf(Function); |
24 |
|
|
}); |
25 |
|
|
}); |