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 toString() output #500

Merged
merged 2 commits into from
Aug 26, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/fake-timers-src.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
/**
* Queues a function to be called during a browser's idle periods
* @callback RequestIdleCallback
* @param {function(IdleDeadline)} callback

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

View workflow job for this annotation

GitHub Actions / lint

Syntax error in type: function(IdleDeadline)
* @param {{timeout: number}} options - an options object
* @returns {number} the id
*/
Expand All @@ -51,13 +51,13 @@

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

Check warning on line 54 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 60 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 @@ -348,7 +348,7 @@
return timer && timer.callAt >= from && timer.callAt <= to;
}

/**

Check warning on line 351 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 @@ -428,7 +428,7 @@
* @param {number} minute
* @param {number} second
* @param {number} ms
* @returns void

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

View workflow job for this annotation

GitHub Actions / lint

Missing JSDoc @returns type
*/
// eslint-disable-next-line no-unused-vars
constructor(year, month, date, hour, minute, second, ms) {
Expand Down Expand Up @@ -456,11 +456,15 @@
};
}

ClockDate.toString = function toString() {
return NativeDate.toString();
};

// noinspection UnnecessaryLocalVariableJS
/**
* A normal Class constructor cannot be called without `new`, but Date can, so we need
* to wrap it in a Proxy in order to ensure this functionality of Date is kept intact
* @type {ClockDate}

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

View workflow job for this annotation

GitHub Actions / lint

The type 'ClockDate' is undefined
*/
const ClockDateProxy = new Proxy(ClockDate, {
// handler for [[Call]] invocations (i.e. not using `new`)
Expand Down Expand Up @@ -656,7 +660,7 @@
}

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

Check warning on line 663 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
* @param {Timer} b
Expand Down Expand Up @@ -787,7 +791,7 @@
}
}

/**

Check warning on line 794 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 @@ -798,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 @@ -809,7 +813,7 @@
return `set${ttype}`;
}

/**

Check warning on line 816 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 Down Expand Up @@ -1053,6 +1057,9 @@

if (isPresent.setImmediate) {
timers.setImmediate = _global.setImmediate;
}

if (isPresent.clearImmediate) {
timers.clearImmediate = _global.clearImmediate;
}

Expand All @@ -1073,7 +1080,7 @@
}

if (isPresent.queueMicrotask) {
timers.queueMicrotask = true;
timers.queueMicrotask = _global.queueMicrotask;
}

if (isPresent.cancelAnimationFrame) {
Expand Down
14 changes: 10 additions & 4 deletions test/fake-timers-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3358,8 +3358,8 @@ describe("FakeTimers", function () {
});
});

it("mirrors toString", function () {
assert.same(this.clock.Date.toString, Date.toString);
it("mirrors toString output", function () {
assert.same(this.clock.Date.toString(), Date.toString());
});
});

Expand Down Expand Up @@ -6069,12 +6069,18 @@ describe("missing timers", function () {
});

it(`should ignore timers in toFake that are not present in "global" when passed the ignore flag: [${timer}]`, function () {
//refute.exception(function () {
FakeTimers.withGlobal({ Date }).install({
ignoreMissingTimers: true,
toFake: [timer],
});
//});
});
});

it("should throw on trying to use standard timers that are not present on the custom global", function () {
assert.exception(function () {
FakeTimers.withGlobal({ setTimeout, Date }).install({
toFake: ["setInterval"],
});
}, /cannot be faked: 'setInterval'/);
});
});
Loading