seed

Seed utilities for controlling randomness in tests. These can be overridden in tests to provide predictable results.

Description:
  • Seed utilities for controlling randomness in tests. These can be overridden in tests to provide predictable results.

Source:

Methods

(inner) random() → {Number}

Description:
  • Returns a random value (Math.random() by default).

Source:
Example
seed.random()
=> 0.42480169934972056
Returns:

a random number between 0 and 1.0. This can be overridden in tests to control for randomness.

Type
Number

(inner) restore()

Description:
  • Restores the seed functions to their default implementations.

Source:
Example
seed.restore()

(inner) sequence(…values)

Description:
  • Replaces seed.random with a function that cycles through a fixed sequence of values, looping back to the start when exhausted. Useful in tests when a single constant isn't enough to drive realistic variation.

Source:
Examples
seed.sequence(0.1, 0.5, 0.9);
seed.random(); // => 0.1
seed.random(); // => 0.5
seed.random(); // => 0.9
seed.random(); // => 0.1  (loops)

Example usage in a test

beforeEach(() => {
  seed.sequence(0.1, 0.5, 0.9);  // cycles: 0.1 → 0.5 → 0.9 → 0.1 → ...
});
afterEach(() => {
  seed.restore();
});
Parameters:
Name Type Attributes Description
values Number <repeatable>

One or more numbers between 0 and 1.0.

(inner) timestamp() → {Number}

Description:
  • Returns a long value (new Date().getTime() by default).

Source:
Example
seed.timestamp()
=> 1571246424383
Returns:

milliseconds since the epoch. This can be overridden in tests to control for time.

Type
Number