core3-utils

npm version @wixc3/testing on Github

Home > @wixc3/testing

testing package

Utils for making mocha + chai testing easy and fun

Remarks

Env variables

Test timeout manipulation

Steps

Steps are a convenient way to craft async tests. A step has a timeout and a description, making test timeouts easy to understand and debug. Each step timeout auto increases the test timeout, assuring the step will time out before the test

Available steps:

Functions

Function Description
[adjustCurrentTestTimeout(ms)](/core3-utils/testing.adjustcurrenttesttimeout.html) Add ms to current test timeout
[adjustTestsTimeouts()](/core3-utils/testing.adjustteststimeouts.html) Adjust tests timeouts based on DEBUG and TIMEOUT\_MULTIPLIER environment variables
[allWithTimeout(actions)](/core3-utils/testing.allwithtimeout.html) Limits the time a list of promises can take - Note: useable only within a mocha test/hook. The total test timeout will be adjusted to make sure the test will not time out waiting for this step
[chaiRetryPlugin(\_, { flag, inspect })](/core3-utils/testing.chairetryplugin.html) Plugin that allows to re-run function passed to `expect`, in order to achieve that use new `retry` method, retrying would be performed until the result will pass the chained assertion or timeout exceeded or retries limit reached. Should be applied through `Chai.use` function, for example:
[createDisposalGroup(name, constraints)](/core3-utils/testing.createdisposalgroup.html) Creates a new disposal group
[createTestDisposables(disposeHook)](/core3-utils/testing.createtestdisposables.html) Creates a disposable group that will be disposed after the test is done
[debugSafeTimeout(ms, rest)](/core3-utils/testing.debugsafetimeout.html) Creates an object with [scaled](/core3-utils/testing.scaletimeout.html) timeout and adjust the current test timeout accordingly
[defaults()](/core3-utils/testing.defaults.html) default values for steps of the current test
[disposeAfter(disposable, options)](/core3-utils/testing.disposeafter.html)
[getTimeoutScale()](/core3-utils/testing.gettimeoutscale.html)
[initAndDisposeAfter(target, options, args)](/core3-utils/testing.initanddisposeafter.html)
[isDebugMode()](/core3-utils/testing.isdebugmode.html)
[locatorTimeout(ms)](/core3-utils/testing.locatortimeout.html)
[mochaCtx()](/core3-utils/testing.mochactx.html) Active mocha context
[overrideDebugMode(value)](/core3-utils/testing.overridedebugmode.html) override the DEBUG environment variable for the current test
[overrideTimeoutScale(scale)](/core3-utils/testing.overridetimeoutscale.html) Overrides the TIMEOUT\_MULTIPLIER for the current test
[randomizeTestsOrder(shouldRandomize)](/core3-utils/testing.randomizetestsorder.html) Randomizes tests order To avoid confusion, it can only be set once, before the testing begins (i.e. not in a running test)
[scaleTimeout(timeout)](/core3-utils/testing.scaletimeout.html) Scales a timeout based on the TIMEOUT\_MULTIPLIER and DEBUG environment variable
[sleep(ms)](/core3-utils/testing.sleep.html) Resolves after ms milliseconds
[step(action)](/core3-utils/testing.step.html) Adds a step description to a promise if it's rejected \* - Note: useable only within a mocha test/hook. The total test timeout will be adjusted to make sure the test will not time out waiting for this step
[useSafeFakeTimers()](/core3-utils/testing.usesafefaketimers.html) Makes it easy to safely use fake timers
[waitForSpyCall(scope, method)](/core3-utils/testing.waitforspycall.html) Spies on an object method, waiting until it's called. The spy is removed once called
[waitForStubCall(action, waitForAction)](/core3-utils/testing.waitforstubcall.html) Creates a stub, then waits for it to be called
[withTimeout(action)](/core3-utils/testing.withtimeout.html) Limits the time a promise can take - Note: useable only within a mocha test/hook. The total test timeout will be adjusted to make sure the test will not time out waiting for this step

Interfaces

Interface Description
[Info](/core3-utils/testing.info.html) Step info base, added step errors
[PollDefaults](/core3-utils/testing.polldefaults.html) Defaults for poll steps
[PromiseStep](/core3-utils/testing.promisestep.html)
[PromiseWithTimeout](/core3-utils/testing.promisewithtimeout.html) WithTimeout API
[StepBase](/core3-utils/testing.stepbase.html) Common step props
[StepsDefaults](/core3-utils/testing.stepsdefaults.html) Test step defaults
[TimeoutDefaults](/core3-utils/testing.timeoutdefaults.html) Step timeout defaults

Variables

Variable Description
[codeMatchers](/core3-utils/testing.codematchers.html)
[DEFAULT\_DISPOSAL\_GROUP](/core3-utils/testing.default_disposal_group.html)

Type Aliases

Type Alias Description
[Description](/core3-utils/testing.description.html) Sets step description
[Predicate](/core3-utils/testing.predicate.html) A predicate function Any return value other than \*\*false\*\* or throwing is considered as satisfying the predicate
[RetryOptions](/core3-utils/testing.retryoptions.html) The retry options for the `chaiRetryPlugin`. {Object} RetryOptions {number} \[timeout\] - The maximum duration in milliseconds to wait before failing the retry operation. {number} \[retries\] - The number of times to retry the function before failing. {number} \[delay\] - The delay in milliseconds between retries.
[Stub](/core3-utils/testing.stub.html) A generated stub
[Timeout](/core3-utils/testing.timeout.html) Sets step timeout