From 1993703e65a6e2d99012c60a3710018748c111cc Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Thu, 9 May 2019 20:20:29 -0700 Subject: [PATCH] assert,test: complete coverage for AssertionError There were two code branches in lib/internal/assert/assertion_error.js that were not covered by tests. This adds a test to cover the two uncovered branches. The test revealed that there was some missing properties/functaionality in the AssertionError class. So this also adds the missing material. --- lib/internal/assert/assertion_error.js | 2 ++ test/parallel/test-assert-assertion-error.js | 27 ++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 test/parallel/test-assert-assertion-error.js diff --git a/lib/internal/assert/assertion_error.js b/lib/internal/assert/assertion_error.js index 048d7be75fc662..2cbd36c67f8876 100644 --- a/lib/internal/assert/assertion_error.js +++ b/lib/internal/assert/assertion_error.js @@ -14,6 +14,8 @@ let white = ''; const kReadableOperator = { deepStrictEqual: 'Expected values to be strictly deep-equal:', + equal: 'Expected values to be loosely equal:', + notEqualUnequal: 'Expected values not to be loosely equal:', strictEqual: 'Expected values to be strictly equal:', strictEqualObject: 'Expected "actual" to be reference-equal to "expected":', deepEqual: 'Expected values to be loosely deep-equal:', diff --git a/test/parallel/test-assert-assertion-error.js b/test/parallel/test-assert-assertion-error.js new file mode 100644 index 00000000000000..ba39cf18fb5f11 --- /dev/null +++ b/test/parallel/test-assert-assertion-error.js @@ -0,0 +1,27 @@ +'use strict'; +require('../common'); + +// Test some edge cases for AssertionError that are not tested elsewhere. +const assert = require('assert'); + +{ + const err = new assert.AssertionError({ operator: 'equal', + actual: 'come on', + expected: 'fhqwhgads', + }); + + assert.strictEqual(err.message, + "Expected values to be loosely equal:\n\n'come on'\n\n" + + "should loosely equal\n\n'fhqwhgads'"); +} + +{ + const err = new assert.AssertionError({ operator: 'notEqual', + actual: 'come on', + expected: 'fhqwhgads', + }); + + assert.strictEqual(err.message, + 'Expected values not to be loosely equal:\n\n' + + "'come on'\n\nshould not loosely equal\n\n'fhqwhgads'"); +}