| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent bae5de1 commit db73d1c
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -36,19 +36,13 @@ const assert = module.exports = ok; | |||
| 36 | 36 | // both the actual and expected values to the assertion error for | |
| 37 | 37 | // display purposes. | |
| 38 | 38 | ||
| 39 | - function innerFail(actual, expected, message, operator, stackStartFunction) { | ||
| 40 | - if (message instanceof Error) throw message; | ||
| 39 | + function innerFail(obj) { | ||
| 40 | + if (obj.message instanceof Error) throw obj.message; | ||
| 41 | 41 | ||
| 42 | - throw new errors.AssertionError({ | ||
| 43 | - message, | ||
| 44 | - actual, | ||
| 45 | - expected, | ||
| 46 | - operator, | ||
| 47 | - stackStartFunction | ||
| 48 | - }); | ||
| 42 | + throw new errors.AssertionError(obj); | ||
| 49 | 43 | } | |
| 50 | 44 | ||
| 51 | - function fail(actual, expected, message, operator, stackStartFunction) { | ||
| 45 | + function fail(actual, expected, message, operator, stackStartFn) { | ||
| 52 | 46 | const argsLen = arguments.length; | |
| 53 | 47 | ||
| 54 | 48 | if (argsLen === 0) { | |
@@ -60,7 +54,13 @@ function fail(actual, expected, message, operator, stackStartFunction) { | |||
| 60 | 54 | operator = '!='; | |
| 61 | 55 | } | |
| 62 | 56 | ||
| 63 | - innerFail(actual, expected, message, operator, stackStartFunction || fail); | ||
| 57 | + innerFail({ | ||
| 58 | + actual, | ||
| 59 | + expected, | ||
| 60 | + message, | ||
| 61 | + operator, | ||
| 62 | + stackStartFn: stackStartFn || fail | ||
| 63 | + }); | ||
| 64 | 64 | } | |
| 65 | 65 | ||
| 66 | 66 | assert.fail = fail; | |
@@ -75,67 +75,124 @@ assert.AssertionError = errors.AssertionError; | |||
| 75 | 75 | // Pure assertion tests whether a value is truthy, as determined | |
| 76 | 76 | // by !!value. | |
| 77 | 77 | function ok(value, message) { | |
| 78 | - if (!value) innerFail(value, true, message, '==', ok); | ||
| 78 | + if (!value) { | ||
| 79 | + innerFail({ | ||
| 80 | + actual: value, | ||
| 81 | + expected: true, | ||
| 82 | + message, | ||
| 83 | + operator: '==', | ||
| 84 | + stackStartFn: ok | ||
| 85 | + }); | ||
| 86 | + } | ||
| 79 | 87 | } | |
| 80 | 88 | assert.ok = ok; | |
| 81 | 89 | ||
| 82 | 90 | // The equality assertion tests shallow, coercive equality with ==. | |
| 83 | 91 | /* eslint-disable no-restricted-properties */ | |
| 84 | 92 | assert.equal = function equal(actual, expected, message) { | |
| 85 | 93 | // eslint-disable-next-line eqeqeq | |
| 86 | - if (actual != expected) innerFail(actual, expected, message, '==', equal); | ||
| 94 | + if (actual != expected) { | ||
| 95 | + innerFail({ | ||
| 96 | + actual, | ||
| 97 | + expected, | ||
| 98 | + message, | ||
| 99 | + operator: '==', | ||
| 100 | + stackStartFn: equal | ||
| 101 | + }); | ||
| 102 | + } | ||
| 87 | 103 | }; | |
| 88 | 104 | ||
| 89 | 105 | // The non-equality assertion tests for whether two objects are not | |
| 90 | 106 | // equal with !=. | |
| 91 | 107 | assert.notEqual = function notEqual(actual, expected, message) { | |
| 92 | 108 | // eslint-disable-next-line eqeqeq | |
| 93 | 109 | if (actual == expected) { | |
| 94 | - innerFail(actual, expected, message, '!=', notEqual); | ||
| 110 | + innerFail({ | ||
| 111 | + actual, | ||
| 112 | + expected, | ||
| 113 | + message, | ||
| 114 | + operator: '!=', | ||
| 115 | + stackStartFn: notEqual | ||
| 116 | + }); | ||
| 95 | 117 | } | |
| 96 | 118 | }; | |
| 97 | 119 | ||
| 98 | 120 | // The equivalence assertion tests a deep equality relation. | |
| 99 | 121 | assert.deepEqual = function deepEqual(actual, expected, message) { | |
| 100 | 122 | if (!isDeepEqual(actual, expected)) { | |
| 101 | - innerFail(actual, expected, message, 'deepEqual', deepEqual); | ||
| 123 | + innerFail({ | ||
| 124 | + actual, | ||
| 125 | + expected, | ||
| 126 | + message, | ||
| 127 | + operator: 'deepEqual', | ||
| 128 | + stackStartFn: deepEqual | ||
| 129 | + }); | ||
| 102 | 130 | } | |
| 103 | 131 | }; | |
| 104 | 132 | ||
| 105 | 133 | // The non-equivalence assertion tests for any deep inequality. | |
| 106 | 134 | assert.notDeepEqual = function notDeepEqual(actual, expected, message) { | |
| 107 | 135 | if (isDeepEqual(actual, expected)) { | |
| 108 | - innerFail(actual, expected, message, 'notDeepEqual', notDeepEqual); | ||
| 136 | + innerFail({ | ||
| 137 | + actual, | ||
| 138 | + expected, | ||
| 139 | + message, | ||
| 140 | + operator: 'notDeepEqual', | ||
| 141 | + stackStartFn: notDeepEqual | ||
| 142 | + }); | ||
| 109 | 143 | } | |
| 110 | 144 | }; | |
| 111 | 145 | /* eslint-enable */ | |
| 112 | 146 | ||
| 113 | 147 | assert.deepStrictEqual = function deepStrictEqual(actual, expected, message) { | |
| 114 | 148 | if (!isDeepStrictEqual(actual, expected)) { | |
| 115 | - innerFail(actual, expected, message, 'deepStrictEqual', deepStrictEqual); | ||
| 149 | + innerFail({ | ||
| 150 | + actual, | ||
| 151 | + expected, | ||
| 152 | + message, | ||
| 153 | + operator: 'deepStrictEqual', | ||
| 154 | + stackStartFn: deepStrictEqual | ||
| 155 | + }); | ||
| 116 | 156 | } | |
| 117 | 157 | }; | |
| 118 | 158 | ||
| 119 | 159 | assert.notDeepStrictEqual = notDeepStrictEqual; | |
| 120 | 160 | function notDeepStrictEqual(actual, expected, message) { | |
| 121 | 161 | if (isDeepStrictEqual(actual, expected)) { | |
| 122 | - innerFail(actual, expected, message, 'notDeepStrictEqual', | ||
| 123 | - notDeepStrictEqual); | ||
| 162 | + innerFail({ | ||
| 163 | + actual, | ||
| 164 | + expected, | ||
| 165 | + message, | ||
| 166 | + operator: 'notDeepStrictEqual', | ||
| 167 | + stackStartFn: notDeepStrictEqual | ||
| 168 | + }); | ||
| 124 | 169 | } | |
| 125 | 170 | } | |
| 126 | 171 | ||
| 127 | 172 | // The strict equality assertion tests strict equality, as determined by ===. | |
| 128 | 173 | assert.strictEqual = function strictEqual(actual, expected, message) { | |
| 129 | 174 | if (actual !== expected) { | |
| 130 | - innerFail(actual, expected, message, '===', strictEqual); | ||
| 175 | + innerFail({ | ||
| 176 | + actual, | ||
| 177 | + expected, | ||
| 178 | + message, | ||
| 179 | + operator: '===', | ||
| 180 | + stackStartFn: strictEqual | ||
| 181 | + }); | ||
| 131 | 182 | } | |
| 132 | 183 | }; | |
| 133 | 184 | ||
| 134 | 185 | // The strict non-equality assertion tests for strict inequality, as | |
| 135 | 186 | // determined by !==. | |
| 136 | 187 | assert.notStrictEqual = function notStrictEqual(actual, expected, message) { | |
| 137 | 188 | if (actual === expected) { | |
| 138 | - innerFail(actual, expected, message, '!==', notStrictEqual); | ||
| 189 | + innerFail({ | ||
| 190 | + actual, | ||
| 191 | + expected, | ||
| 192 | + message, | ||
| 193 | + operator: '!==', | ||
| 194 | + stackStartFn: notStrictEqual | ||
| 195 | + }); | ||
| 139 | 196 | } | |
| 140 | 197 | }; | |
| 141 | 198 | ||
@@ -183,18 +240,27 @@ function innerThrows(shouldThrow, block, expected, message) { | |||
| 183 | 240 | details += ` (${expected.name})`; | |
| 184 | 241 | } | |
| 185 | 242 | details += message ? `: ${message}` : '.'; | |
| 186 | - fail(actual, expected, `Missing expected exception${details}`, 'throws'); | ||
| 243 | + innerFail({ | ||
| 244 | + actual, | ||
| 245 | + expected, | ||
| 246 | + operator: 'throws', | ||
| 247 | + message: `Missing expected exception${details}`, | ||
| 248 | + stackStartFn: innerThrows | ||
| 249 | + }); | ||
| 187 | 250 | } | |
| 188 | 251 | if (expected && expectedException(actual, expected) === false) { | |
| 189 | 252 | throw actual; | |
| 190 | 253 | } | |
| 191 | 254 | } else if (actual !== undefined) { | |
| 192 | 255 | if (!expected || expectedException(actual, expected)) { | |
| 193 | 256 | details = message ? `: ${message}` : '.'; | |
| 194 | - fail(actual, | ||
| 195 | - expected, | ||
| 196 | - `Got unwanted exception${details}\n${actual.message}`, | ||
| 197 | - 'doesNotThrow'); | ||
| 257 | + innerFail({ | ||
| 258 | + actual, | ||
| 259 | + expected, | ||
| 260 | + operator: 'doesNotThrow', | ||
| 261 | + message: `Got unwanted exception${details}\n${actual.message}`, | ||
| 262 | + stackStartFn: innerThrows | ||
| 263 | + }); | ||
| 198 | 264 | } | |
| 199 | 265 | throw actual; | |
| 200 | 266 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -83,7 +83,7 @@ class AssertionError extends Error { | |||
| 83 | 83 | if (typeof options !== 'object' || options === null) { | |
| 84 | 84 | throw new exports.TypeError('ERR_INVALID_ARG_TYPE', 'options', 'Object'); | |
| 85 | 85 | } | |
| 86 | - var { actual, expected, message, operator, stackStartFunction } = options; | ||
| 86 | + var { actual, expected, message, operator, stackStartFn } = options; | ||
| 87 | 87 | if (message) { | |
| 88 | 88 | super(message); | |
| 89 | 89 | } else { | |
@@ -102,7 +102,7 @@ class AssertionError extends Error { | |||
| 102 | 102 | this.actual = actual; | |
| 103 | 103 | this.expected = expected; | |
| 104 | 104 | this.operator = operator; | |
| 105 | - Error.captureStackTrace(this, stackStartFunction); | ||
| 105 | + Error.captureStackTrace(this, stackStartFn); | ||
| 106 | 106 | } | |
| 107 | 107 | } | |
| 108 | 108 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,6 @@ | |||
| 1 | 1 | Exiting with code=1 | |
| 2 | 2 | assert.js:* | |
| 3 | - throw new errors.AssertionError({ | ||
| 3 | + throw new errors.AssertionError(obj); | ||
| 4 | 4 | ^ | |
| 5 | 5 | ||
| 6 | 6 | AssertionError [ERR_ASSERTION]: 1 === 2 | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -780,3 +780,12 @@ common.expectsError( | |||
| 780 | 780 | /* eslint-enable no-restricted-properties */ | |
| 781 | 781 | assert(7); | |
| 782 | 782 | } | |
| 783 | + | ||
| 784 | + common.expectsError( | ||
| 785 | + () => assert.ok(null), | ||
| 786 | + { | ||
| 787 | + code: 'ERR_ASSERTION', | ||
| 788 | + type: assert.AssertionError, | ||
| 789 | + message: 'null == true' | ||
| 790 | + } | ||
| 791 | + ); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments