Skip to content

Commit

Permalink
Add test from jestjs/jest#14549
Browse files Browse the repository at this point in the history
  • Loading branch information
fatso83 committed Oct 19, 2023
1 parent f6ef392 commit 33d3c5b
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions test/issue-async.test.js
Original file line number Diff line number Diff line change
@@ -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();
//});

0 comments on commit 33d3c5b

Please sign in to comment.