{
  "source": "doc/api/assert.markdown",
  "modules": [
    {
      "textRaw": "Assert",
      "name": "assert",
      "stability": 3,
      "stabilityText": "Locked",
      "desc": "<p>The <code>assert</code> module provides a simple set of assertion tests that can be used to\ntest invariants. The module is intended for internal use by Node.js, but can be\nused in application code via <code>require(&#39;assert&#39;)</code>. However, <code>assert</code> is not a\ntesting framework, and is not intended to be used as a general purpose assertion\nlibrary.\n\n</p>\n<p>The API for the <code>assert</code> module is [Locked][]. This means that there will be no\nadditions or changes to any of the methods implemented and exposed by\nthe module.\n\n</p>\n",
      "methods": [
        {
          "textRaw": "assert(value[, message]), assert.ok(value[, message])",
          "type": "method",
          "name": "ok",
          "desc": "<p>Tests if <code>value</code> is truthy. It is equivalent to\n<code>assert.equal(!!value, true, message)</code>.\n\n</p>\n<p>If <code>value</code> is not truthy, an <code>AssertionError</code> is thrown with a <code>message</code>\nproperty set equal to the value of the <code>message</code> parameter. If the <code>message</code>\nparameter is <code>undefined</code>, a default error message is assigned.\n\n</p>\n<pre><code>const assert = require(&#39;assert&#39;);\n\nassert(true);  // OK\nassert(1);     // OK\nassert(false);\n  // throws &quot;AssertionError: false == true&quot;\nassert(0);\n  // throws &quot;AssertionError: 0 == true&quot;\nassert(false, &#39;it\\&#39;s false&#39;);\n  // throws &quot;AssertionError: it&#39;s false&quot;\n\nassert.ok(true);  // OK\nassert.ok(1);     // OK\nassert.ok(false);\n  // throws &quot;AssertionError: false == true&quot;\nassert.ok(0);\n  // throws &quot;AssertionError: 0 == true&quot;\nassert.ok(false, &#39;it\\&#39;s false&#39;);\n  // throws &quot;AssertionError: it&#39;s false&quot;</code></pre>\n",
          "signatures": [
            {
              "params": [
                {
                  "name": "value"
                },
                {
                  "name": "message])"
                },
                {
                  "name": "assert.ok(value"
                },
                {
                  "name": "message",
                  "optional": true
                }
              ]
            }
          ]
        },
        {
          "textRaw": "assert.deepEqual(actual, expected[, message])",
          "type": "method",
          "name": "deepEqual",
          "desc": "<p>Tests for deep equality between the <code>actual</code> and <code>expected</code> parameters.\nPrimitive values are compared with the equal comparison operator ( <code>==</code> ).\n\n</p>\n<p>Only enumerable &quot;own&quot; properties are considered. The <code>deepEqual()</code>\nimplementation does not test object prototypes, attached symbols, or\nnon-enumerable properties. This can lead to some potentially surprising\nresults. For example, the following example does not throw an <code>AssertionError</code>\nbecause the properties on the [<code>Error</code>][] object are non-enumerable:\n\n</p>\n<pre><code>// WARNING: This does not throw an AssertionError!\nassert.deepEqual(Error(&#39;a&#39;), Error(&#39;b&#39;));</code></pre>\n<p>&quot;Deep&quot; equality means that the enumerable &quot;own&quot; properties of child objects\nare evaluated also:\n\n</p>\n<pre><code>const assert = require(&#39;assert&#39;);\n\nconst obj1 = {\n  a : {\n    b : 1\n  }\n};\nconst obj2 = {\n  a : {\n    b : 2\n  }\n};\nconst obj3 = {\n  a : {\n    b : 1\n  }\n}\nconst obj4 = Object.create(obj1);\n\nassert.deepEqual(obj1, obj1);\n  // OK, object is equal to itself\n\nassert.deepEqual(obj1, obj2);\n  // AssertionError: { a: { b: 1 } } deepEqual { a: { b: 2 } }\n  // values of b are different\n\nassert.deepEqual(obj1, obj3);\n  // OK, objects are equal\n\nassert.deepEqual(obj1, obj4);\n  // AssertionError: { a: { b: 1 } } deepEqual {}\n  // Prototypes are ignored</code></pre>\n<p>If the values are not equal, an <code>AssertionError</code> is thrown with a <code>message</code>\nproperty set equal to the value of the <code>message</code> parameter. If the <code>message</code>\nparameter is undefined, a default error message is assigned.\n\n</p>\n",
          "signatures": [
            {
              "params": [
                {
                  "name": "actual"
                },
                {
                  "name": "expected"
                },
                {
                  "name": "message",
                  "optional": true
                }
              ]
            }
          ]
        },
        {
          "textRaw": "assert.deepStrictEqual(actual, expected[, message])",
          "type": "method",
          "name": "deepStrictEqual",
          "desc": "<p>Generally identical to <code>assert.deepEqual</code> with the exception that primitive\nvalues are compared using the strict equality operator ( <code>===</code> ).\n\n</p>\n<pre><code>const assert = require(&#39;assert&#39;);\n\nassert.deepEqual({a:1}, {a:&#39;1&#39;});\n  // OK, because 1 == &#39;1&#39;\n\nassert.deepStrictEqual({a:1}, {a:&#39;1&#39;});\n  // AssertionError: { a: 1 } deepStrictEqual { a: &#39;1&#39; }\n  // because 1 !== &#39;1&#39; using strict equality</code></pre>\n<p>If the values are not equal, an <code>AssertionError</code> is thrown with a <code>message</code>\nproperty set equal to the value of the <code>message</code> parameter. If the <code>message</code>\nparameter is undefined, a default error message is assigned.\n\n</p>\n",
          "signatures": [
            {
              "params": [
                {
                  "name": "actual"
                },
                {
                  "name": "expected"
                },
                {
                  "name": "message",
                  "optional": true
                }
              ]
            }
          ]
        },
        {
          "textRaw": "assert.doesNotThrow(block[, error][, message])",
          "type": "method",
          "name": "doesNotThrow",
          "desc": "<p>Asserts that the function <code>block</code> does not throw an error. See\n[<code>assert.throws()</code>][] for more details.\n\n</p>\n<p>When <code>assert.doesNotThrow()</code> is called, it will immediately call the <code>block</code>\nfunction.\n\n</p>\n<p>If an error is thrown and it is the same type as that specified by the <code>error</code>\nparameter, then an <code>AssertionError</code> is thrown. If the error is of a different\ntype, or if the <code>error</code> parameter is undefined, the error is propagated back\nto the caller.\n\n</p>\n<p>The following, for instance, will throw the [<code>TypeError</code>][] because there is no\nmatching error type in the assertion:\n\n</p>\n<pre><code>assert.doesNotThrow(\n  function() {\n    throw new TypeError(&#39;Wrong value&#39;);\n  },\n  SyntaxError\n);</code></pre>\n<p>However, the following will result in an <code>AssertionError</code> with the message\n&#39;Got unwanted exception (TypeError)..&#39;:\n\n</p>\n<pre><code>assert.doesNotThrow(\n  function() {\n    throw new TypeError(&#39;Wrong value&#39;);\n  },\n  TypeError\n);</code></pre>\n<p>If an <code>AssertionError</code> is thrown and a value is provided for the <code>message</code>\nparameter, the value of <code>message</code> will be appended to the <code>AssertionError</code>\nmessage:\n\n</p>\n<pre><code>assert.doesNotThrow(\n  function() {\n    throw new TypeError(&#39;Wrong value&#39;);\n  },\n  TypeError,\n  &#39;Whoops&#39;\n);\n// Throws: AssertionError: Got unwanted exception (TypeError). Whoops</code></pre>\n",
          "signatures": [
            {
              "params": [
                {
                  "name": "block"
                },
                {
                  "name": "error",
                  "optional": true
                },
                {
                  "name": "message",
                  "optional": true
                }
              ]
            }
          ]
        },
        {
          "textRaw": "assert.equal(actual, expected[, message])",
          "type": "method",
          "name": "equal",
          "desc": "<p>Tests shallow, coercive equality between the <code>actual</code> and <code>expected</code> parameters\nusing the equal comparison operator ( <code>==</code> ).\n\n</p>\n<pre><code>const assert = require(&#39;assert&#39;);\n\nassert.equal(1, 1);\n  // OK, 1 == 1\nassert.equal(1, &#39;1&#39;);\n  // OK, 1 == &#39;1&#39;\n\nassert.equal(1, 2);\n  // AssertionError: 1 == 2\nassert.equal({a: {b: 1}}, {a: {b: 1}});\n  //AssertionError: { a: { b: 1 } } == { a: { b: 1 } }</code></pre>\n<p>If the values are not equal, an <code>AssertionError</code> is thrown with a <code>message</code>\nproperty set equal to the value of the <code>message</code> parameter. If the <code>message</code>\nparameter is undefined, a default error message is assigned.\n\n</p>\n",
          "signatures": [
            {
              "params": [
                {
                  "name": "actual"
                },
                {
                  "name": "expected"
                },
                {
                  "name": "message",
                  "optional": true
                }
              ]
            }
          ]
        },
        {
          "textRaw": "assert.fail(actual, expected, message, operator)",
          "type": "method",
          "name": "fail",
          "desc": "<p>Throws an <code>AssertionError</code>. If <code>message</code> is falsy, the error message is set as\nthe values of <code>actual</code> and <code>expected</code> separated by the provided <code>operator</code>.\nOtherwise, the error message is the value of <code>message</code>.\n\n</p>\n<pre><code>const assert = require(&#39;assert&#39;);\n\nassert.fail(1, 2, undefined, &#39;&gt;&#39;);\n  // AssertionError: 1 &gt; 2\n\nassert.fail(1, 2, &#39;whoops&#39;, &#39;&gt;&#39;);\n  // AssertionError: whoops</code></pre>\n",
          "signatures": [
            {
              "params": [
                {
                  "name": "actual"
                },
                {
                  "name": "expected"
                },
                {
                  "name": "message"
                },
                {
                  "name": "operator"
                }
              ]
            }
          ]
        },
        {
          "textRaw": "assert.ifError(value)",
          "type": "method",
          "name": "ifError",
          "desc": "<p>Throws <code>value</code> if <code>value</code> is truthy. This is useful when testing the <code>error</code>\nargument in callbacks.\n\n</p>\n<pre><code>const assert = require(&#39;assert&#39;);\n\nassert.ifError(0); // OK\nassert.ifError(1); // Throws 1\nassert.ifError(&#39;error&#39;) // Throws &#39;error&#39;\nassert.ifError(new Error()); // Throws Error</code></pre>\n",
          "signatures": [
            {
              "params": [
                {
                  "name": "value"
                }
              ]
            }
          ]
        },
        {
          "textRaw": "assert.notDeepEqual(actual, expected[, message])",
          "type": "method",
          "name": "notDeepEqual",
          "desc": "<p>Tests for any deep inequality. Opposite of [<code>assert.deepEqual</code>][].\n\n</p>\n<pre><code>const assert = require(&#39;assert&#39;);\n\nconst obj1 = {\n  a : {\n    b : 1\n  }\n};\nconst obj2 = {\n  a : {\n    b : 2\n  }\n};\nconst obj3 = {\n  a : {\n    b : 1\n  }\n}\nconst obj4 = Object.create(obj1);\n\nassert.deepEqual(obj1, obj1);\n  AssertionError: { a: { b: 1 } } notDeepEqual { a: { b: 1 } }\n\nassert.deepEqual(obj1, obj2);\n  // OK, obj1 and obj2 are not deeply equal\n\nassert.deepEqual(obj1, obj3);\n  // AssertionError: { a: { b: 1 } } notDeepEqual { a: { b: 1 } }\n\nassert.deepEqual(obj1, obj4);\n  // OK, obj1 and obj2 are not deeply equal</code></pre>\n<p>If the values are deeply equal, an <code>AssertionError</code> is thrown with a <code>message</code>\nproperty set equal to the value of the <code>message</code> parameter. If the <code>message</code>\nparameter is undefined, a default error message is assigned.\n\n</p>\n",
          "signatures": [
            {
              "params": [
                {
                  "name": "actual"
                },
                {
                  "name": "expected"
                },
                {
                  "name": "message",
                  "optional": true
                }
              ]
            }
          ]
        },
        {
          "textRaw": "assert.notDeepStrictEqual(actual, expected[, message])",
          "type": "method",
          "name": "notDeepStrictEqual",
          "desc": "<p>Tests for deep strict inequality. Opposite of [<code>assert.deepStrictEqual</code>][].\n\n</p>\n<pre><code>const assert = require(&#39;assert&#39;);\n\nassert.notDeepEqual({a:1}, {a:&#39;1&#39;});\n  // AssertionError: { a: 1 } notDeepEqual { a: &#39;1&#39; }\n\nassert.notDeepStrictEqual({a:1}, {a:&#39;1&#39;});\n  // OK</code></pre>\n<p>If the values are deeply and strictly equal, an <code>AssertionError</code> is thrown\nwith a <code>message</code> property set equal to the value of the <code>message</code> parameter. If\nthe <code>message</code> parameter is undefined, a default error message is assigned.\n\n</p>\n",
          "signatures": [
            {
              "params": [
                {
                  "name": "actual"
                },
                {
                  "name": "expected"
                },
                {
                  "name": "message",
                  "optional": true
                }
              ]
            }
          ]
        },
        {
          "textRaw": "assert.notEqual(actual, expected[, message])",
          "type": "method",
          "name": "notEqual",
          "desc": "<p>Tests shallow, coercive inequality with the not equal comparison operator\n( <code>!=</code> ).\n\n</p>\n<pre><code>const assert = require(&#39;assert&#39;);\n\nassert.notEqual(1, 2);\n  // OK\n\nassert.notEqual(1, 1);\n  // AssertionError: 1 != 1\n\nassert.notEqual(1, &#39;1&#39;);\n  // AssertionError: 1 != &#39;1&#39;</code></pre>\n<p>If the values are equal, an <code>AssertionError</code> is thrown with a <code>message</code>\nproperty set equal to the value of the <code>message</code> parameter. If the <code>message</code>\nparameter is undefined, a default error message is assigned.\n\n</p>\n",
          "signatures": [
            {
              "params": [
                {
                  "name": "actual"
                },
                {
                  "name": "expected"
                },
                {
                  "name": "message",
                  "optional": true
                }
              ]
            }
          ]
        },
        {
          "textRaw": "assert.notStrictEqual(actual, expected[, message])",
          "type": "method",
          "name": "notStrictEqual",
          "desc": "<p>Tests strict inequality as determined by the strict not equal operator\n( <code>!==</code> ).\n\n</p>\n<pre><code>const assert = require(&#39;assert&#39;);\n\nassert.notStrictEqual(1, 2);\n  // OK\n\nassert.notStrictEqual(1, 1);\n  // AssertionError: 1 != 1\n\nassert.notStrictEqual(1, &#39;1&#39;);\n  // OK</code></pre>\n<p>If the values are strictly equal, an <code>AssertionError</code> is thrown with a\n<code>message</code> property set equal to the value of the <code>message</code> parameter. If the\n<code>message</code> parameter is undefined, a default error message is assigned.\n\n</p>\n",
          "signatures": [
            {
              "params": [
                {
                  "name": "actual"
                },
                {
                  "name": "expected"
                },
                {
                  "name": "message",
                  "optional": true
                }
              ]
            }
          ]
        },
        {
          "textRaw": "assert.strictEqual(actual, expected[, message])",
          "type": "method",
          "name": "strictEqual",
          "desc": "<p>Tests strict equality as determined by the strict equality operator ( <code>===</code> ).\n\n</p>\n<pre><code>const assert = require(&#39;assert&#39;);\n\nassert.strictEqual(1, 2);\n  // AssertionError: 1 === 2\n\nassert.strictEqual(1, 1);\n  // OK\n\nassert.strictEqual(1, &#39;1&#39;);\n  // AssertionError: 1 === &#39;1&#39;</code></pre>\n<p>If the values are not strictly equal, an <code>AssertionError</code> is thrown with a\n<code>message</code> property set equal to the value of the <code>message</code> parameter. If the\n<code>message</code> parameter is undefined, a default error message is assigned.\n\n</p>\n",
          "signatures": [
            {
              "params": [
                {
                  "name": "actual"
                },
                {
                  "name": "expected"
                },
                {
                  "name": "message",
                  "optional": true
                }
              ]
            }
          ]
        },
        {
          "textRaw": "assert.throws(block[, error][, message])",
          "type": "method",
          "name": "throws",
          "desc": "<p>Expects the function <code>block</code> to throw an error. If specified, <code>error</code> can be a\nconstructor, [<code>RegExp</code>][], or validation function.\n\n</p>\n<p>Validate instanceof using constructor:\n\n</p>\n<pre><code>assert.throws(\n  function() {\n    throw new Error(&#39;Wrong value&#39;);\n  },\n  Error\n);</code></pre>\n<p>Validate error message using [<code>RegExp</code>][]:\n\n</p>\n<pre><code>assert.throws(\n  function() {\n    throw new Error(&#39;Wrong value&#39;);\n  },\n  /value/\n);</code></pre>\n<p>Custom error validation:\n\n</p>\n<pre><code>assert.throws(\n  function() {\n    throw new Error(&#39;Wrong value&#39;);\n  },\n  function(err) {\n    if ( (err instanceof Error) &amp;&amp; /value/.test(err) ) {\n      return true;\n    }\n  },\n  &#39;unexpected error&#39;\n);</code></pre>\n",
          "signatures": [
            {
              "params": [
                {
                  "name": "block"
                },
                {
                  "name": "error",
                  "optional": true
                },
                {
                  "name": "message",
                  "optional": true
                }
              ]
            }
          ]
        }
      ],
      "type": "module",
      "displayName": "Assert"
    }
  ]
}
