Do not let constructor appear in Object.getOwnPropertyNames for fake Dates#567
Open
tommie-lie wants to merge 1 commit intosinonjs:mainfrom
Open
Do not let constructor appear in Object.getOwnPropertyNames for fake Dates#567tommie-lie wants to merge 1 commit intosinonjs:mainfrom
tommie-lie wants to merge 1 commit intosinonjs:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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, namelyconstructor.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 relatedgetOwnProperty*functions).Solution - optional
As the fix from #511/#513 only overrides the
constructorproperty 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 asnew ClockDate().