Socket
Book a DemoInstallSign in
Socket

@dazl/testing

Package Overview
Dependencies
Maintainers
33
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dazl/testing

Making mocha/chai testing easier

Source
npmnpm
Version
18.5.0
Version published
Weekly downloads
529
-42.06%
Maintainers
33
Weekly downloads
 
Created
Source

npm version @dazl/testing on Github

Home > @dazl/testing

testing package

Utils for making mocha + chai testing easy and fun

Remarks

Env variables

  • DEBUG=true/positive number env variable will set test timeouts and time scale to infinity so tests (that don't explicitly override timeout) will not time out on breakpoints

  • TIMEOUT_MULTIPLIER=number env variable will multiply all test timeouts by the given number

Test timeout manipulation

  • scaleTimeout() multiplies timeouts when debugging or running on slow CI machines, based on TIMEOUT_MULTIPLIER and DEBUG env variables

  • adjusts current test timeout (for use in non step async actions)

  • locatorTimeout() creates a locator timeout and adjust the current test

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

FunctionDescription
adjustCurrentTestTimeout(ms)Add ms to current test timeout
adjustTestsTimeouts()Adjust tests timeouts based on DEBUG and TIMEOUT_MULTIPLIER environment variables
allWithTimeout(actions)

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 })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)Creates a new disposal group
createTestDisposables(disposeHook)Creates a disposable group that will be disposed after the test is done
debugSafeTimeout(ms, rest)Creates an object with scaled timeout and adjust the current test timeout accordingly
defaults()default values for steps of the current test
disposeAfter(disposable, options)
getTimeoutScale()
initAndDisposeAfter(target, options, args)
isDebugMode()
locatorTimeout(ms)
mochaCtx()Active mocha context
overrideDebugMode(value)override the DEBUG environment variable for the current test
overrideTimeoutScale(scale)Overrides the TIMEOUT_MULTIPLIER for the current test
randomizeTestsOrder(shouldRandomize)

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)Scales a timeout based on the TIMEOUT_MULTIPLIER and DEBUG environment variable
sleep(ms)Resolves after ms milliseconds
step(action)

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()Makes it easy to safely use fake timers
waitForSpyCall(scope, method)Spies on an object method, waiting until it's called. The spy is removed once called
waitForStubCall(action, waitForAction)Creates a stub, then waits for it to be called
withTimeout(action)

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

InterfaceDescription
InfoStep info base, added step errors
PollDefaultsDefaults for poll steps
PromiseStep
PromiseWithTimeoutWithTimeout API
StepBaseCommon step props
StepsDefaultsTest step defaults
TimeoutDefaultsStep timeout defaults

Variables

VariableDescription
codeMatchers
DEFAULT_DISPOSAL_GROUP

Type Aliases

Type AliasDescription
DescriptionSets step description
Predicate

A predicate function

Any return value other than **false** or throwing is considered as satisfying the predicate

RetryOptions

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.

StubA generated stub
TimeoutSets step timeout

FAQs

Package last updated on 04 Sep 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts