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

Ensure checks based Object.keys length pass for fake Dates #513

Merged
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
5 changes: 4 additions & 1 deletion src/fake-timers-src.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
*/

/**
* Queues a function to be called during a browser's idle periods

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

View workflow job for this annotation

GitHub Actions / lint

Expected only 0 line after block description
*
* @callback RequestIdleCallback
* @param {function(IdleDeadline)} callback

Check warning on line 28 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 @@ -52,13 +52,13 @@

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

Check warning on line 55 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 61 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 @@ -105,7 +105,7 @@
/* eslint-enable jsdoc/require-property-description */

/**
* Configuration object for the `install` method.

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

View workflow job for this annotation

GitHub Actions / lint

Expected only 0 line after block description
*
* @typedef {object} Config
* @property {number|Date} [now] a number (in milliseconds) or a Date object (default epoch)
Expand All @@ -119,7 +119,7 @@

/* eslint-disable jsdoc/require-property-description */
/**
* The internal structure to describe a scheduled fake timer

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

View workflow job for this annotation

GitHub Actions / lint

Expected only 0 line after block description
*
* @typedef {object} Timer
* @property {Function} func
Expand All @@ -133,7 +133,7 @@
*/

/**
* A Node timer

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

View workflow job for this annotation

GitHub Actions / lint

Expected only 0 line after block description
*
* @typedef {object} NodeImmediate
* @property {function(): boolean} hasRef
Expand All @@ -145,7 +145,7 @@
/* eslint-disable complexity */

/**
* Mocks available features in the specified global namespace.

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

View workflow job for this annotation

GitHub Actions / lint

Expected only 0 line after block description
*
* @param {*} _global Namespace to mock (e.g. `window`)
* @returns {FakeTimers}
Expand Down Expand Up @@ -275,7 +275,7 @@
/**
* Parse strings like "01:10:00" (meaning 1 hour, 10 minutes, 0 seconds) into
* number of milliseconds. This is used to support human-readable strings passed
* to clock.tick()

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

View workflow job for this annotation

GitHub Actions / lint

Expected only 0 line after block description
*
* @param {string} str
* @returns {number}
Expand Down Expand Up @@ -311,7 +311,7 @@
}

/**
* Get the decimal part of the millisecond value as nanoseconds

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

View workflow job for this annotation

GitHub Actions / lint

Expected only 0 line after block description
*
* @param {number} msFloat the number of milliseconds
* @returns {number} an integer number of nanoseconds in the range [0,1e6)
Expand Down Expand Up @@ -450,7 +450,10 @@

// ensures identity checks using the constructor prop still works
// this should have no other functional effect
this.constructor = NativeDate;
Object.defineProperty(this, "constructor", {
value: NativeDate,
enumerable: false,
});
}

static [Symbol.hasInstance](instance) {
Expand Down
6 changes: 6 additions & 0 deletions test/fake-timers-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3212,6 +3212,12 @@ describe("FakeTimers", function () {
assert.equals(date.constructor, realDate.constructor);
});

it("creates Date objects where the constructor prop is not enumerable", function () {
const date = new this.clock.Date();

assert.equals(Object.keys(date).length, 0);
});

it("creates Date objects representing clock time", function () {
const date = new this.clock.Date();

Expand Down
Loading