Skip to content

Commit 0318a15

Browse files
docs: explain how RandomMocker can be used
1 parent e4a8846 commit 0318a15

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

docs/curriculum-helpers.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
# Curriculum Helpers
22

3+
## RandomMocker
4+
5+
Mocks Math.random for testing purposes. Each time `mock()` is called the pseudo-random number generator is reset to its initial state, so that the same sequence of random numbers is generated each time. `restore()` restores the native Math.random function.
6+
7+
```javascript
8+
const randomMocker = new RandomMocker();
9+
randomMocker.mock();
10+
Math.random(); // first call is always 0.2523451747838408
11+
Math.random(); // second call is always 0.08812504541128874
12+
randomMocker.mock();
13+
Math.random(); // generator is reset, so we get 0.2523451747838408 again
14+
randomMocker.restore();
15+
Math.random(); // back to native Math.random
16+
```
17+
318
## concatRegex
419

520
Combines one or more regular expressions into one.

0 commit comments

Comments
 (0)