-
Notifications
You must be signed in to change notification settings - Fork 107
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
Create fake timers based on passed in object #146
Comments
For context, @SimenB is a core dev for the Jest testing solution. Jest is looking to adopt |
Sure @jdalton @SimenB I think we can do that. The way I see it - we'd either pass the object to Alternatively, we can expose a factory on
That should let you pass @fatso83 if this sounds good to you - I can open a PR for this if you'd like - shouldn't be too much work to add. |
Yeah, that's the alternative, but I was hoping to offload all of that logic onto Lolex. One issue with manually setting the globals is that Just to clarify, I'm a collaborator on Jest, but I don't work for FB 🙂 |
You're right: var timeoutResult = setTimeout(NOOP, 0);
var addTimerReturnsObject = typeof timeoutResult === "object"; If we extract things to a factory this should work out of the box - although it should probably be changed to |
I thought this was the intent of using |
What about |
Seems ok, but the API looks a tad bit weird/inconsistent when considering that we return a clock object from
|
var clock = lolex.install({global: window}); can also be done (API wise) if you prefer |
I think that is preferable, if possible? Seems consistent. Other views? |
I like it. That means we do var clock = lolex.install({global: this._global, target: this._global}); right? One thing is that in Jest we want the ability to install and uninstall often, and it's wasteful to calculate from globals every time. But I doubt it's measurable |
Any news here? Would love this to land so I can start testing this within Jest. I've started a tiny bit (jestjs/jest#5171) and the amount of code deletion (and extra features) is absolutely lovely! |
No need to apologize, a timeline is more than enough for me. Enjoy your travels! 🙂 |
Going to take a look |
Looking at this, it seems like it's just a bug with |
I don't think so. See the following lines: https://github.com/sinonjs/lolex/blob/444c9384ace3853761d76aa31fa4ac3648247c9d/lolex.js#L31-L37 They look at the global |
@SimenB thinking about this further, I think the issue is just whether or not we should return object or DOM timers - so I think I'll just PR that functionality instead. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Discussion still ongoing in the PR |
Fixes sinonjs#146 Closes sinonjs#157
For people following along, I've opened up a PR containing my suggestion from the OP - a factory function. #164 |
Fixes sinonjs#146 Closes sinonjs#157
Fixes sinonjs#146 Closes sinonjs#157
Bad title, so I'll try to describe my use case.
If I create a JSDOM instance in node, it has
requestAnimationFrame
, but lolex is unable to discover this (unless I use some fancyvm
code) as is inspectsglobal
atrequire
-time. This means that I have to uselolex
inside of the script I execute in JSDOM, instead of managing it from the outside by controlling the injected globals. I need this as I'm looking to use Lolex directly in Jest.I'm thinking something like
const clockFactory = lolex.createClockFactoryFrom(global)
or something, which can be separately used later in for instanceconst clock = clockFactory.install({ target: myTarget });
The text was updated successfully, but these errors were encountered: