From 33d3c5b2df2251d4d8ffe863769d4f32ebfc5d2c Mon Sep 17 00:00:00 2001 From: Carl-Erik Kopseng Date: Thu, 5 Oct 2023 23:34:48 +0200 Subject: [PATCH] Add test from https://github.com/jestjs/jest/issues/14549 --- test/issue-async.test.js | 49 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 test/issue-async.test.js diff --git a/test/issue-async.test.js b/test/issue-async.test.js new file mode 100644 index 0000000..8f28fb5 --- /dev/null +++ b/test/issue-async.test.js @@ -0,0 +1,49 @@ +"use strict"; + +const FakeTimers = require("../src/fake-timers-src"); +const sinon = require("sinon"); +const assert = require("assert"); + +/** + * + * @param cb + */ +function myFn(cb) { + queueMicrotask(() => cb()); +} + +describe("bug", function () { + let clock; + const timers = ["runAll", "runToLast", "runAllAsync", "runToLastAsync"]; + + afterEach(function () { + clock.uninstall(); + }); + + beforeEach(function setup() { + clock = FakeTimers.install(); + }); + + timers.forEach((asyncFastForward) => { + it(`should advance past queued microtasks using ${asyncFastForward}`, async function () { + const cb = sinon.fake(); + myFn(cb); + await clock[asyncFastForward](); + assert.equal(cb.callCount, 1); + }); + }); +}); + +//it.each([ +//() => jest.advanceTimersToNextTimer(), +//() => jest.advanceTimersByTime(1), +//() => jest.runAllTimers(), +//() => jest.runAllTicks(), +//() => jest.runOnlyPendingTimers(), +//])("should advance past queued microtasks using %s", (syncFastForward) => { +//jest.useFakeTimers(); +//const cb = jest.fn(); +//myFn(cb); +//syncFastForward(); +//expect(cb).toHaveBeenCalled(); +//});