-
Notifications
You must be signed in to change notification settings - Fork 39
Description
The only way the tests pass while the onFulfilled and onRejected functions are not invoked synchronously is when the onFulfilled and onRejected functions are delayed specifically with queueMicrotask.
While the linked spec for the exercise doesn't specifically mention queueMicrotask instead it mentions: setTimeout, setImmediate, proccess.nextTick which by the spec are valid ways of making sure onFulfilled and onRejected are not called synchronously:
https://promisesaplus.com/#point-67:~:text=Here%20%E2%80%9Cplatform%20code,handlers%20are%20called.
promises-training/src/tests/foundation/promise.test.ts
Lines 60 to 61 in 58d11d3
| await waitForPromises(); | |
| const nextPromise = promise.then(onFulfilled, onRejected); |
promises-training/src/tests/foundation/promise.test.ts
Lines 95 to 100 in 58d11d3
| it("`.then` onFulfilled gets called with resolved value", async () => { | |
| const { onFulfilled, resolvedValue } = await thirdSetup(); | |
| expect(onFulfilled).toHaveBeenCalledTimes(1); | |
| expect(onFulfilled).toHaveBeenCalledWith(resolvedValue); | |
| }); |