[Pkg-javascript-commits] [node-tap] 21/186: Add t.resolves, t.resolveMatch

Bastien Roucariès rouca at moszumanska.debian.org
Fri Dec 1 16:40:39 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 7ba5b93be6ccd050330b1f001fcc9316959b1b02
Author: isaacs <i at izs.me>
Date:   Mon Sep 4 18:46:51 2017 -0700

    Add t.resolves, t.resolveMatch
    
    Fix #401
---
 lib/test.js | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 51 insertions(+), 1 deletion(-)

diff --git a/lib/test.js b/lib/test.js
index 5b16a65..fbd75dd 100644
--- a/lib/test.js
+++ b/lib/test.js
@@ -1217,13 +1217,63 @@ class Test extends Base {
           if (Object.prototype.toString.call(wanted) === '[object RegExp]') {
             return t.match(er.message, wanted, message, extra)
           }
-          return t.has(er, wanted, message, extra)
+          return t.match(er, wanted, message, extra)
         } else {
           return t.pass(message, extra)
         }
       })
     })
   }
+
+  resolves (promise, message, extra) {
+    if (!this.currentAssert)
+      this.currentAssert = Test.prototype.rejects
+
+    if (message && typeof message === 'object')
+      extra = message, message = ''
+
+    if (!extra)
+      extra = {}
+
+    if (!message)
+      message = 'expect resolving Promise'
+
+    if (!promise || typeof promise.then !== 'function')
+      return this.fail(message, extra)
+
+    // have to do as a subtest, because promises are async
+    extra.at = stack.at(this.currentAssert)
+    this.test(message, { buffered: true }, t =>
+      promise.then(value => {
+        extra.found = value
+        t.pass(message, extra)
+      }))
+  }
+
+  resolveMatch (promise, wanted, message, extra) {
+    if (!this.currentAssert)
+      this.currentAssert = Test.prototype.rejects
+
+    if (message && typeof message === 'object')
+      extra = message, message = ''
+
+    if (!extra)
+      extra = {}
+
+    if (!message)
+      message = 'expect resolving Promise'
+
+    if (!promise || typeof promise.then !== 'function')
+      return this.fail(message, extra)
+
+    // have to do as a subtest, because promises are async
+    extra.at = stack.at(this.currentAssert)
+    this.test(message, { buffered: true }, t =>
+      promise.then(value => {
+        extra.found = value
+        t.match(value, wanted, extra)
+      }))
+  }
 }
 
 const endAllQueue = queue => {

-- 
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