Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for #483 and jestjs/jest#14549 #485

Merged
merged 5 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/fake-timers-src.js
Expand Up @@ -47,13 +47,13 @@

/**
* @typedef RequestAnimationFrame
* @property {function(number):void} requestAnimationFrame

Check warning on line 50 in src/fake-timers-src.js

View workflow job for this annotation

GitHub Actions / lint

Missing JSDoc @Property "requestAnimationFrame" description
* @returns {number} - the id
*/

/**
* @typedef Performance
* @property {function(): number} now

Check warning on line 56 in src/fake-timers-src.js

View workflow job for this annotation

GitHub Actions / lint

Missing JSDoc @Property "now" description
*/

/* eslint-disable jsdoc/require-property-description */
Expand Down Expand Up @@ -307,7 +307,7 @@
return timer && timer.callAt >= from && timer.callAt <= to;
}

/**

Check warning on line 310 in src/fake-timers-src.js

View workflow job for this annotation

GitHub Actions / lint

Missing JSDoc @returns declaration
* @param {Clock} clock
* @param {Timer} job
*/
Expand Down Expand Up @@ -658,7 +658,7 @@
}

/* eslint consistent-return: "off" */
/**

Check warning on line 661 in src/fake-timers-src.js

View workflow job for this annotation

GitHub Actions / lint

JSDoc @returns declaration present but return expression not available in function
* Timer comparitor
*
* @param {Timer} a
Expand Down Expand Up @@ -790,7 +790,7 @@
}
}

/**

Check warning on line 793 in src/fake-timers-src.js

View workflow job for this annotation

GitHub Actions / lint

Missing JSDoc @returns declaration
* Gets clear handler name for a given timer type
*
* @param {string} ttype
Expand All @@ -802,7 +802,7 @@
return `clear${ttype}`;
}

/**

Check warning on line 805 in src/fake-timers-src.js

View workflow job for this annotation

GitHub Actions / lint

Missing JSDoc @returns declaration
* Gets schedule handler name for a given timer type
*
* @param {string} ttype
Expand All @@ -814,7 +814,7 @@
return `set${ttype}`;
}

/**

Check warning on line 817 in src/fake-timers-src.js

View workflow job for this annotation

GitHub Actions / lint

Missing JSDoc @returns declaration
* Creates an anonymous function to warn only once
*/
function createWarnOnce() {
Expand All @@ -826,7 +826,7 @@
}
const warnOnce = createWarnOnce();

/**

Check warning on line 829 in src/fake-timers-src.js

View workflow job for this annotation

GitHub Actions / lint

Missing JSDoc @returns declaration
* @param {Clock} clock
* @param {number} timerId
* @param {string} ttype
Expand Down Expand Up @@ -1015,8 +1015,8 @@

/**
* @typedef {object} Timers
* @property {setTimeout} setTimeout

Check warning on line 1018 in src/fake-timers-src.js

View workflow job for this annotation

GitHub Actions / lint

Missing JSDoc @Property "setTimeout" description
* @property {clearTimeout} clearTimeout

Check warning on line 1019 in src/fake-timers-src.js

View workflow job for this annotation

GitHub Actions / lint

Missing JSDoc @Property "clearTimeout" description
* @property {setInterval} setInterval
* @property {clearInterval} clearInterval
* @property {Date} Date
Expand Down Expand Up @@ -1578,6 +1578,8 @@
function doRun() {
originalSetTimeout(function () {
try {
runJobs(clock);

let numTimers;
if (i < clock.loopLimit) {
if (!clock.timers) {
Expand Down Expand Up @@ -1633,6 +1635,7 @@
try {
const timer = lastTimer(clock);
if (!timer) {
runJobs(clock);
resolve(clock.now);
}

Expand Down
34 changes: 34 additions & 0 deletions test/issue-483-test.js
@@ -0,0 +1,34 @@
"use strict";

const FakeTimers = require("../src/fake-timers-src");
const sinon = require("sinon");
const assert = require("assert");

function myFn(cb) {
queueMicrotask(() => cb());
}

describe("async time skippers should run microtasks", function () {
let clock;
const timers = ["runAllAsync", "runToLastAsync"];

afterEach(function () {
clock.uninstall();
});

beforeEach(function setup() {
clock = FakeTimers.install({ toFake: ["queueMicrotask"] });
});

// eslint-disable-next-line mocha/no-setup-in-describe
timers.forEach((fastForward) => {
it(`should advance past queued microtasks using ${fastForward}`, async function () {
const cb = sinon.fake();
myFn(cb);
myFn(cb);
myFn(cb);
await clock[fastForward]();
assert.equal(cb.callCount, 3);
});
});
});