[Pkg-javascript-commits] [node-tap] 60/186: coverage for t.throws()

Bastien Roucariès rouca at moszumanska.debian.org
Fri Dec 1 16:40:43 UTC 2017


This is an automated email from the git hooks/post-receive script.

rouca pushed a commit to branch master
in repository node-tap.

commit 60b0c38578648b67f54bd8e8b9aeaabbda49d467
Author: isaacs <i at izs.me>
Date:   Sat Nov 4 17:33:35 2017 -0700

    coverage for t.throws()
---
 lib/test.js                       | 11 ++------
 tap-snapshots/unit-test.js-TAP.js | 54 +++++++++++++++++++++++++++++++++++++++
 unit/test.js                      | 25 ++++++++++++++++++
 3 files changed, 81 insertions(+), 9 deletions(-)

diff --git a/lib/test.js b/lib/test.js
index 9614b25..8030fb6 100644
--- a/lib/test.js
+++ b/lib/test.js
@@ -1094,9 +1094,6 @@ class Test extends Base {
       }
     }
 
-    if (message && typeof message === 'object')
-      extra = message, message = ''
-
     if (!extra)
       extra = {}
 
@@ -1114,21 +1111,17 @@ class Test extends Base {
 
         // intentionally copying non-local properties, since this
         // is an Error object, and those are funky.
-        for (i in wanted) {
+        for (let i in wanted) {
           w[i] = wanted[i]
         }
         wanted = w
 
         message += ': ' + (wanted.name || 'Error') + ' ' + wanted.message
-        extra = extra || {}
-        if (extra !== wanted) {
-          extra.wanted = wanted
-        }
+        extra.wanted = wanted
       }
     }
 
     if (typeof fn !== 'function') {
-      extra = extra || {}
       extra.todo = true
       return this.pass(message, extra)
     }
diff --git a/tap-snapshots/unit-test.js-TAP.js b/tap-snapshots/unit-test.js-TAP.js
index a1f9c3f..01d28e2 100644
--- a/tap-snapshots/unit-test.js-TAP.js
+++ b/tap-snapshots/unit-test.js-TAP.js
@@ -1041,3 +1041,57 @@ ok 12 - type is EventEmitter
 # failed 3 of 12 tests
 
 `
+
+exports[`unit/test.js TAP assertion checks throws > throws 1`] = `
+TAP version 13
+ok 1 - expected to throw
+ok 2 - expected to throw
+ok 3 - expected to throw: TypeError x
+ok 4 - expected to throw
+not ok 5 - expected to throw: Error x
+  ---
+  wanted:
+    message: x
+    name: ''
+  found:
+  stack: |
+{STACK}
+  pattern:
+    message: x
+    name: ''
+  at:
+    line: #
+    column: #
+    file: unit/test.js
+    function: throws
+  stack: |
+{STACK}
+  source: |
+    tt.throws(() => { throw new Error('x') }, nameless)
+  ...
+
+ok 6 - expected to throw
+ok 7 - expected to throw
+ok 8 - expected to throw
+ok 9 - expected to throw # SKIP
+ok 10 - expected to throw
+not ok 11 - extra functions are no-ops for bw comp
+  ---
+  at:
+    line: #
+    column: #
+    file: unit/test.js
+    function: throws
+  stack: |
+{STACK}
+  source: |
+    tt.throws(() => {}, () => {}, () => {}, () => {},
+  ...
+
+ok 12 - todo # TODO
+1..12
+# failed 2 of 12 tests
+# todo: 1
+# skip: 1
+
+`
diff --git a/unit/test.js b/unit/test.js
index e3a04be..b7097f3 100644
--- a/unit/test.js
+++ b/unit/test.js
@@ -264,6 +264,31 @@ t.test('assertion checks', t => {
       tt.type(tt, 'EventEmitter')
       tt.end()
     },
+
+    throws: tt => {
+      tt.throws(() => { throw new TypeError('x') }, TypeError)
+      tt.throws(() => { throw new TypeError('x') }, TypeError)
+      tt.throws(() => { throw new TypeError('x') },
+                new TypeError('x'))
+      tt.throws(() => { throw new TypeError('x') },
+                { message: 'x' })
+
+      const nameless = new Error('x')
+      nameless.name = ''
+      tt.throws(() => { throw new Error('x') }, nameless)
+
+      tt.throws(() => { throw nameless }, { message: 'x' })
+      tt.throws(() => { throw nameless }, /^.$/)
+      tt.throws(() => { throw nameless })
+
+      tt.throws(() => { throw new Error('x') }, {}, { skip: true })
+      tt.throws(() => { throw new Error('x') }, {},
+                {}, {}, 1)
+      tt.throws(() => {}, () => {}, () => {}, () => {},
+                'extra functions are no-ops for bw comp')
+      tt.throws('todo')
+      tt.end()
+    },
   }
 
   const keys = Object.keys(cases)

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-tap.git



More information about the Pkg-javascript-commits mailing list