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

Allow stub or spy Date object safely using a closure to get a clean copy #506

Closed

Conversation

tcorral
Copy link
Contributor

@tcorral tcorral commented Jan 24, 2014

Hi, I'm using Jasmine for my open source projects and in my job, and I had some problems when trying to stub or spy Date object using Jasmine spies or Sinon.js stubs.
The problem is that Jasmine uses the original Date object for timers and if you stub or spy the object then you can't use Jasmine because it fails when it tries to execute the 'getTime' method.
The solution I propose is to store a clean copy of the original Date object using a closure to store and use it even if the original object has been stubbed or spied in any other test.
I've not created a new test because the original behaviour should became the same.

@infews
Copy link
Contributor

infews commented Jan 24, 2014

Good find. I'll take a deeper look at this shortly.

sheelc added a commit to sheelc/jasmine that referenced this pull request Feb 9, 2014
@sheelc sheelc closed this in b5775ae Feb 9, 2014
@sheelc
Copy link
Contributor

sheelc commented Feb 9, 2014

Changed the implementation slightly since we already had a sufficient place to make the closure but should be merged. Thanks for the PR!

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.

None yet

3 participants