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

Fake timers / mock Date #383

Closed
jsardev opened this issue Sep 27, 2018 · 2 comments
Closed

Fake timers / mock Date #383

jsardev opened this issue Sep 27, 2018 · 2 comments

Comments

@jsardev
Copy link

jsardev commented Sep 27, 2018

Quick question: can I somehow use testdouble to mock out Date? I mean a similiar functionality to sinon fake timers. I tried few approaches with td but it didn't work out 😢

@jsardev jsardev changed the title Fake timers Fake timers / mock Date Sep 27, 2018
@rosston
Copy link
Member

rosston commented Sep 29, 2018

I can’t speak to precisely why testdouble can’t do what you’re trying to do.

But if you haven’t looked at it before, I might suggest looking at the contributing-tests wiki, specifically “Don’t mock what you don’t own”. That whole page is worth reading for the background (and it’s not very long), but the last section suggests a way forward: putting your use of Date in your own wrapper, which you can then design for easy use/mocking.

@jsardev
Copy link
Author

jsardev commented Oct 1, 2018

@rosston That makes sense. I always forget about this rule, but it really makes sense 😄 Thanks!

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

No branches or pull requests

2 participants