From 5e970a1c6674d1f95493d8dc78927757e2845c03 Mon Sep 17 00:00:00 2001 From: estrada9166 Date: Fri, 21 Jun 2019 16:55:38 -0500 Subject: [PATCH 1/4] Improve coverage for assert.ok --- test/parallel/test-assert.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/parallel/test-assert.js b/test/parallel/test-assert.js index cf80cf598d6938..f7aad23bdba6ff 100644 --- a/test/parallel/test-assert.js +++ b/test/parallel/test-assert.js @@ -43,6 +43,7 @@ assert.ok(a.AssertionError.prototype instanceof Error, assert.throws(() => a(false), a.AssertionError, 'ok(false)'); assert.throws(() => a.ok(false), a.AssertionError, 'ok(false)'); +assert.throws(() => a.ok(false, true, new Error('ok(false)')), a.AssertionError); a(true); a('test', 'ok(\'test\')'); From 4a4f668f2ca5297c12db3c30488c47d8e393611a Mon Sep 17 00:00:00 2001 From: estrada9166 Date: Sun, 23 Jun 2019 11:52:24 -0500 Subject: [PATCH 2/4] test: add tests to assert.ok --- test/parallel/test-assert.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/test/parallel/test-assert.js b/test/parallel/test-assert.js index f7aad23bdba6ff..147b69f59f60eb 100644 --- a/test/parallel/test-assert.js +++ b/test/parallel/test-assert.js @@ -43,7 +43,19 @@ assert.ok(a.AssertionError.prototype instanceof Error, assert.throws(() => a(false), a.AssertionError, 'ok(false)'); assert.throws(() => a.ok(false), a.AssertionError, 'ok(false)'); -assert.throws(() => a.ok(false, true, new Error('ok(false)')), a.AssertionError); + +// Throw message if the message is instanceof Error. +{ + let threw = false; + try { + assert.ok(false, new Error('ok(false)')); + } catch (e) { + threw = true; + assert.ok(e instanceof Error); + } + assert.ok(threw, 'Error: ok(true)'); +} + a(true); a('test', 'ok(\'test\')'); From 62084f41f298380ce93ece14351e266a0d917381 Mon Sep 17 00:00:00 2001 From: estrada9166 Date: Sun, 23 Jun 2019 12:15:54 -0500 Subject: [PATCH 3/4] assert: add tests to assert.ok and improve coverage Refs: https://coverage.nodejs.org/coverage-1a4f27ae21698d0c/lib/assert.js.html#L364 --- test/parallel/test-assert.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/parallel/test-assert.js b/test/parallel/test-assert.js index 147b69f59f60eb..32b2bca6415811 100644 --- a/test/parallel/test-assert.js +++ b/test/parallel/test-assert.js @@ -53,7 +53,7 @@ assert.throws(() => a.ok(false), a.AssertionError, 'ok(false)'); threw = true; assert.ok(e instanceof Error); } - assert.ok(threw, 'Error: ok(true)'); + assert.ok(threw, 'Error: ok(false)'); } From e8077ebd08eacb96a5d05e477dc7b1fa4023f428 Mon Sep 17 00:00:00 2001 From: estrada9166 Date: Sun, 23 Jun 2019 22:55:32 -0500 Subject: [PATCH 4/4] assert: add test to doesNotThrow; validate if actual with regex. Refs: https://coverage.nodejs.org/coverage-1a4f27ae21698d0c/lib/assert.js.html#L736 --- test/parallel/test-assert.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test/parallel/test-assert.js b/test/parallel/test-assert.js index 32b2bca6415811..2959f54c7a1c4a 100644 --- a/test/parallel/test-assert.js +++ b/test/parallel/test-assert.js @@ -178,6 +178,17 @@ assert.throws( } ); +assert.throws( + () => a.doesNotThrow(() => thrower(Error), /\[[a-z]{6}\s[A-z]{6}\]/g, 'user message'), + { + name: 'AssertionError', + code: 'ERR_ASSERTION', + operator: 'doesNotThrow', + message: 'Got unwanted exception: user message\n' + + 'Actual message: "[object Object]"' + } +); + // Make sure that validating using constructor really works. { let threw = false;