Skip to content

Do not let constructor appear in Object.getOwnPropertyNames for fake Dates#567

Open
tommie-lie wants to merge 1 commit intosinonjs:mainfrom
tommie-lie:main
Open

Do not let constructor appear in Object.getOwnPropertyNames for fake Dates#567
tommie-lie wants to merge 1 commit intosinonjs:mainfrom
tommie-lie:main

Conversation

@tommie-lie
Copy link
Copy Markdown

Purpose (TL;DR) - mandatory

Fix checks that rely on Object.getOwnPropertyNames(date) to behave like native Dates.

Background (Problem in detail) - optional

In our codebase, we use deep-freeze-es6 to freeze objects containing Date instances. In their code, there is something along the lines Object.getOwnPropertyNames(dateInstance).forEach(...) which does nothing for native date instances. When using fake timers, the loop contains exactly one property, namely constructor.
The constructor property was added in #511 and fixed for Object.keys() in #513.
This PR fixes the same issue as #513 but for Object.getOwnPropertyNames() (and related getOwnProperty* functions).

Solution - optional

As the fix from #511/#513 only overrides the constructor property on the instance without actually changing the real constructor, my fix now sets the constructor property on the prototype class. This has no influence on new instances as new ClockDate().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant