Skip to content
Advertisement

Tag: unit-testing

Mocking globals in Jest

Is there any way in Jest to mock global objects, such as navigator, or Image*? I’ve pretty much given up on this, and left it up to a series of mockable utility methods. For example: Testing this tiny function is simple, but crufty and not deterministic at all. I can get 75% of the way there, but this is about

How do I stub a chain of methods in Sinon?

I know how to use stub to replace one function. But now I have a line in my function I want to test that I need to stub that looks like this So there is a chain of function here and I’m unsure what I need to do. How do I stub “find” to return something that I can use

Change default timeout for mocha

If we have a unit test file my-spec.js and running with mocha: The default timeout will be 2000 ms. It can be overwritten for partial test with a command line parameter: Is it possible to change the default timeout globally for all tests? i.e. the default timeout value will be different from 2000 ms when you call: Answer By default

Advertisement