![]() Saying notEqual is implying that you are testing specifically for an inequality, while notOk doesn't really make sense. Not OK implies failure, and so the failure of a notOk function might have just seemed a little convoluted.Īs for the other methods having their not equivalents, I think the language is still meaningful. To have included a notOk() function would imply some ambiguous meaning. The above makes sense semantically, as you are still testing the truthiness of your expression, it just so happens that you are expecting it to be false. So while your usage of !myValue is valid, I think it would be more appropriate to write: assert.ok(myValue = false) It is expecting a statement to which you want to test the truthiness of. It should be noted that while the function is called ok(), that does not mean that it is expecting a true value from your code. ![]() This appears to simply be a convenience function. ok(value, message) is equivalent to assert.equal(!!value, true, message). operator Set to the passed in operator value.If you look at the docs, it notes that.code Value is always ERR_ASSERTION to show that the error is an. ![]() generatedMessage Indicates if the message was auto-generated.expected Set to the expected value for methods such as.actual Set to the actual argument for methods such as.stackStartFn If provided, the generated stack trace omitsĪ subclass of Error that indicates the failure of an assertion.Īll instances contain the built-in Error properties ( message and name).operator The operator property on the error instance.expected The expected property on the error instance.actual The actual property on the error instance.message If provided, the error message is set to this value.Will be instances of the AssertionError class. deepEqual( /a/gi, new Date()) Class: assert.AssertionError # Lax: // WARNING: This does not throw an AssertionError!Īssert. This isĮspecially true for epEqual(), where the comparison rules are Otherwise, theĪbstract Equality Comparison may cause surprising results. Whenever possible, use the strict assertion mode instead. To use legacy assertion mode: const assert = require( 'assert') Legacy assertion mode uses the Abstract Equality Comparison in: More on color support in terminal environments, read the tty This will also deactivate the colors in the REPL. To deactivate the colors, use the NO_COLOR or NODE_DISABLE_COLORSĮnvironment variables. ![]() AssertionError: Expected inputs to be strictly deep-equal: // + actual - expected. strict Įxample error diff: const assert = require( 'assert'). To use strict assertion mode: const assert = require( 'assert'). In legacyĪssertion mode, error messages for objects display the objects, often truncated. In strict assertion mode, error messages for objects display a diff. In strict assertion mode, non-strict methods behave like their corresponding assert.strictEqual(actual, expected)Ĭhanged "strict mode" to "strict assertion mode" and "legacy mode" to "legacy assertion mode" to avoid confusion with the more usual meaning of "strict mode".Īdded error diffs to the strict assertion mode.Īdded strict assertion mode to the assert module.assert.notStrictEqual(actual, expected).assert.notDeepStrictEqual(actual, expected).
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |