Skip to content

Commit 1c679a0

Browse files
committed
Document strict mode in readme
1 parent 2e887c8 commit 1c679a0

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,43 @@ This module is used for writing unit tests for your applications, you can access
77
It aims to be fully compatibe with the [node.js assert module](http://nodejs.org/api/assert.html), same API and same behavior, just adding support for web browsers.
88
The API and code may contain traces of the [CommonJS Unit Testing 1.0 spec](http://wiki.commonjs.org/wiki/Unit_Testing/1.0) which they were based on, but both have evolved significantly since then.
99

10+
A `strict` and a `legacy` mode exist, while it is recommended to only use `strict mode`.
11+
12+
## Strict mode
13+
14+
When using the `strict mode`, any `assert` function will use the equality used in the strict function mode. So `assert.deepEqual()` will, for example, work the same as `assert.deepStrictEqual()`.
15+
16+
It can be accessed using:
17+
18+
```js
19+
const assert = require('assert').strict;
20+
```
21+
22+
## Legacy mode
23+
24+
> Deprecated: Use strict mode instead.
25+
26+
When accessing `assert` directly instead of using the `strict` property, the
27+
[Abstract Equality Comparison](https://tc39.github.io/ecma262/#sec-abstract-equality-comparison) will be used for any function without a
28+
"strict" in its name (e.g. `assert.deepEqual()`).
29+
30+
It can be accessed using:
31+
32+
```js
33+
const assert = require('assert');
34+
```
35+
36+
It is recommended to use the `strict mode` instead as the Abstract Equality Comparison can often have surprising results. Especially
37+
in case of `assert.deepEqual()` as the used comparison rules there are very lax.
38+
39+
E.g.
40+
41+
```js
42+
// WARNING: This does not throw an AssertionError!
43+
assert.deepEqual(/a/gi, new Date());
44+
```
45+
46+
1047
## assert.fail(actual, expected, message, operator)
1148
Throws an exception that displays the values for actual and expected separated by the provided operator.
1249

0 commit comments

Comments
 (0)