@@ -13,6 +13,70 @@ A `strict` and a `legacy` mode exist, while it is recommended to only use
1313For more information about the used equality comparisons see
1414[ MDN's guide on equality comparisons and sameness] [ mdn-equality-guide ] .
1515
16+ ## Class: assert.AssertionError
17+
18+ A subclass of ` Error ` that indicates the failure of an assertion. All errors
19+ thrown by the ` assert ` module will be instances of the ` AssertionError ` class.
20+
21+ ### new assert.AssertionError(options)
22+ <!-- YAML
23+ added: v0.1.21
24+ -->
25+ * ` options ` {Object}
26+ * ` message ` {string} If provided, the error message is going to be set to this
27+ value.
28+ * ` actual ` {any} The ` actual ` property on the error instance is going to
29+ contain this value. Internally used for the ` actual ` error input in case
30+ e.g., [ ` assert.strictEqual() ` ] is used.
31+ * ` expected ` {any} The ` expected ` property on the error instance is going to
32+ contain this value. Internally used for the ` expected ` error input in case
33+ e.g., [ ` assert.strictEqual() ` ] is used.
34+ * ` operator ` {string} The ` operator ` property on the error instance is going
35+ to contain this value. Internally used to indicate what operation was used
36+ for comparison (or what assertion function triggered the error).
37+ * ` stackStartFn ` {Function} If provided, the generated stack trace is going to
38+ remove all frames up to the provided function.
39+
40+ A subclass of ` Error ` that indicates the failure of an assertion.
41+
42+ All instances contain the built-in ` Error ` properties (` message ` and ` name ` )
43+ and:
44+
45+ * ` actual ` {any} Set to the actual value in case e.g.,
46+ [ ` assert.strictEqual() ` ] is used.
47+ * ` expected ` {any} Set to the expected value in case e.g.,
48+ [ ` assert.strictEqual() ` ] is used.
49+ * ` generatedMessage ` {boolean} Indicates if the message was auto-generated
50+ (` true ` ) or not.
51+ * ` code ` {string} This is always set to the string ` ERR_ASSERTION ` to indicate
52+ that the error is actually an assertion error.
53+ * ` operator ` {string} Set to the passed in operator value.
54+
55+ ``` js
56+ const assert = require (' assert' );
57+
58+ // Generate an AssertionError to compare the error message later:
59+ const { message } = new assert.AssertionError ({
60+ actual: 1 ,
61+ expected: 2 ,
62+ operator: ' strictEqual'
63+ });
64+
65+ // Verify error output:
66+ try {
67+ assert .strictEqual (1 , 2 );
68+ } catch (err) {
69+ assert (err instanceof assert .AssertionError );
70+ assert .strictEqual (err .message , message);
71+ assert .strictEqual (err .name , ' AssertionError [ERR_ASSERTION]' );
72+ assert .strictEqual (err .actual , 1 );
73+ assert .strictEqual (err .expected , 2 );
74+ assert .strictEqual (err .code , ' ERR_ASSERTION' );
75+ assert .strictEqual (err .operator , ' strictEqual' );
76+ assert .strictEqual (err .generatedMessage , true );
77+ }
78+ ```
79+
1680## Strict mode
1781<!-- YAML
1882added: v9.9.0
0 commit comments