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

Factory method to create delay implementation with bound timer methods #39

Closed
novemberborn opened this issue Sep 13, 2018 · 7 comments
Closed

Comments

@novemberborn
Copy link
Contributor

It'd be useful if I could do the following:

import { factory } from 'delay'

const delay = factory({ setTimeout, clearTimeout })

Since this binds the implementation to the timer methods I've provided, I can then safely stub the timers using say lolex and still use the delay interface.

@sindresorhus
Copy link
Owner

Sure

@Torgen
Copy link
Contributor

Torgen commented Jun 5, 2019

This breaks using sinon.useFakeTimers(), as setTimeout and cancelTimeout are captured before sinon can stub them out.

@novemberborn
Copy link
Contributor Author

This breaks using sinon.useFakeTimers(), as setTimeout and cancelTimeout are captured before sinon can stub them out.

That's kinda the point of this feature. It should only be used though when you're actively trying to avoid stubbing.

@Torgen
Copy link
Contributor

Torgen commented Jun 7, 2019 via email

@novemberborn
Copy link
Contributor Author

No it should use the global methods by default.

@Torgen
Copy link
Contributor

Torgen commented Jun 7, 2019 via email

@novemberborn
Copy link
Contributor Author

Ah of course, thanks for pointing that out! Yea that's not what I intended. Probably best to open a new issue for that. I'm sure @sindresorhus would appreciate a PR as well if you have some thoughts on how to fix this.

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

No branches or pull requests

3 participants