|
| 1 | +*node-api-assert.txt* For Node.js module `Assert` version v3.3.0. |
| 2 | + |
| 3 | +Node.js Documentation |
| 4 | +https://nodejs.org |
| 5 | + |
| 6 | +============================================================================== |
| 7 | +CONTENTS *node-api-contents* |
| 8 | + |
| 9 | + 1. Intro |node-api-assert| |
| 10 | + 2. Methods |node-api-assert-methods| |
| 11 | + 2.1. assert.fail(actual, expected, message, operator) |node-api-assert.fail()| |
| 12 | + 2.2. assert(value[, message]), assert.ok(value[, message]) |node-api-assert.ok()| |
| 13 | + 2.3. assert.equal(actual, expected[, message]) |node-api-assert.equal()| |
| 14 | + 2.4. assert.notEqual(actual, expected[, message]) |node-api-assert.notEqual()| |
| 15 | + 2.5. assert.deepEqual(actual, expected[, message]) |node-api-assert.deepEqual()| |
| 16 | + 2.6. assert.notDeepEqual(actual, expected[, message]) |node-api-assert.notDeepEqual()| |
| 17 | + 2.7. assert.strictEqual(actual, expected[, message]) |node-api-assert.strictEqual()| |
| 18 | + 2.8. assert.notStrictEqual(actual, expected[, message]) |node-api-assert.notStrictEqual()| |
| 19 | + 2.9. assert.deepStrictEqual(actual, expected[, message]) |node-api-assert.deepStrictEqual()| |
| 20 | + 2.10. assert.notDeepStrictEqual(actual, expected[, message]) |node-api-assert.notDeepStrictEqual()| |
| 21 | + 2.11. assert.throws(block[, error][, message]) |node-api-assert.throws()| |
| 22 | + 2.12. assert.doesNotThrow(block[, message]) |node-api-assert.doesNotThrow()| |
| 23 | + 2.13. assert.ifError(value) |node-api-assert.ifError()| |
| 24 | + 3. Properties |node-api-assert-properties| |
| 25 | + |
| 26 | +============================================================================== |
| 27 | +INTRO *node-api-assert* |
| 28 | + |
| 29 | +Stability: 2 - Stable |
| 30 | + |
| 31 | +This module is used for writing unit tests for your applications, you can |
| 32 | +access it with `require('assert')`. |
| 33 | + |
| 34 | +============================================================================== |
| 35 | +METHODS *node-api-assert-methods* |
| 36 | + |
| 37 | +------------------------------------------------------------------------------ |
| 38 | +assert.fail(actual, expected, message, operator) *node-api-assert.fail()* |
| 39 | + |
| 40 | +Throws an exception that displays the values for `actual` and `expected` separated by the provided operator. |
| 41 | + |
| 42 | + |
| 43 | +------------------------------------------------------------------------------ |
| 44 | +assert(value[, message]), assert.ok(value[, message]) *node-api-assert.ok()* |
| 45 | + |
| 46 | +Tests if value is truthy, it is equivalent to `assert.equal(true, !!value, message);` |
| 47 | + |
| 48 | + |
| 49 | +------------------------------------------------------------------------------ |
| 50 | +assert.equal(actual, expected[, message]) *node-api-assert.equal()* |
| 51 | + |
| 52 | +Tests shallow, coercive equality with the equal comparison operator ( `==` ). |
| 53 | + |
| 54 | + |
| 55 | +------------------------------------------------------------------------------ |
| 56 | +assert.notEqual(actual, expected[, message]) *node-api-assert.notEqual()* |
| 57 | + |
| 58 | +Tests shallow, coercive non-equality with the not equal comparison operator ( `!=` ). |
| 59 | + |
| 60 | + |
| 61 | +------------------------------------------------------------------------------ |
| 62 | +assert.deepEqual(actual, expected[, message]) *node-api-assert.deepEqual()* |
| 63 | + |
| 64 | +Tests for deep equality. Primitive values are compared with the equal comparison |
| 65 | +operator ( `==` ). Doesn't take object prototypes into account. |
| 66 | + |
| 67 | + |
| 68 | +------------------------------------------------------------------------------ |
| 69 | +assert.notDeepEqual(actual, expected[, message]) *node-api-assert.notDeepEqual()* |
| 70 | + |
| 71 | +Tests for any deep inequality. Opposite of `assert.deepEqual`. |
| 72 | + |
| 73 | + |
| 74 | +------------------------------------------------------------------------------ |
| 75 | +assert.strictEqual(actual, expected[, message]) *node-api-assert.strictEqual()* |
| 76 | + |
| 77 | +Tests strict equality, as determined by the strict equality operator ( `===` ) |
| 78 | + |
| 79 | + |
| 80 | +------------------------------------------------------------------------------ |
| 81 | +assert.notStrictEqual(actual, expected[, message]) *node-api-assert.notStrictEqual()* |
| 82 | + |
| 83 | +Tests strict non-equality, as determined by the strict not equal |
| 84 | +operator ( `!==` ) |
| 85 | + |
| 86 | + |
| 87 | +------------------------------------------------------------------------------ |
| 88 | +assert.deepStrictEqual(actual, expected[, message]) *node-api-assert.deepStrictEqual()* |
| 89 | + |
| 90 | +Tests for deep equality. Primitive values are compared with the strict equality |
| 91 | +operator ( `===` ). |
| 92 | + |
| 93 | + |
| 94 | +------------------------------------------------------------------------------ |
| 95 | +assert.notDeepStrictEqual(actual, expected[, message]) *node-api-assert.notDeepStrictEqual()* |
| 96 | + |
| 97 | +Tests for deep inequality. Opposite of `assert.deepStrictEqual`. |
| 98 | + |
| 99 | + |
| 100 | +------------------------------------------------------------------------------ |
| 101 | +assert.throws(block[, error][, message]) *node-api-assert.throws()* |
| 102 | + |
| 103 | +Expects `block` to throw an error. `error` can be constructor, `RegExp` or |
| 104 | +validation function. |
| 105 | + |
| 106 | +Validate instanceof using constructor: |
| 107 | + |
| 108 | + > |
| 109 | + assert.throws( |
| 110 | + function() { |
| 111 | + throw new Error("Wrong value"); |
| 112 | + }, |
| 113 | + Error |
| 114 | + ); |
| 115 | +< |
| 116 | + |
| 117 | +Validate error message using RegExp: |
| 118 | + |
| 119 | + > |
| 120 | + assert.throws( |
| 121 | + function() { |
| 122 | + throw new Error("Wrong value"); |
| 123 | + }, |
| 124 | + /value/ |
| 125 | + ); |
| 126 | +< |
| 127 | + |
| 128 | +Custom error validation: |
| 129 | + |
| 130 | + > |
| 131 | + assert.throws( |
| 132 | + function() { |
| 133 | + throw new Error("Wrong value"); |
| 134 | + }, |
| 135 | + function(err) { |
| 136 | + if ( (err instanceof Error) && /value/.test(err) ) { |
| 137 | + return true; |
| 138 | + } |
| 139 | + }, |
| 140 | + "unexpected error" |
| 141 | + ); |
| 142 | +< |
| 143 | + |
| 144 | + |
| 145 | +------------------------------------------------------------------------------ |
| 146 | +assert.doesNotThrow(block[, message]) *node-api-assert.doesNotThrow()* |
| 147 | + |
| 148 | +Expects `block` not to throw an error, see `assert.throws` for details. |
| 149 | + |
| 150 | + |
| 151 | +------------------------------------------------------------------------------ |
| 152 | +assert.ifError(value) *node-api-assert.ifError()* |
| 153 | + |
| 154 | +Tests if value is not a false value, throws if it is a true value. Useful when |
| 155 | +testing the first argument, `error` in callbacks. |
| 156 | + |
| 157 | + |
| 158 | + |
| 159 | +============================================================================== |
| 160 | +PROPERTIES *node-api-assert-properties* |
| 161 | + |
| 162 | + vim:tw=78:ts=8:ft=help |
0 commit comments