Skip to content

Commit

Permalink
Fix coverage for define-assertion promise handling
Browse files Browse the repository at this point in the history
  • Loading branch information
mantoni committed Oct 2, 2020
1 parent a0c54a3 commit a02ff67
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions lib/add.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"use strict";

var assert = require("assert");
var sinon = require("sinon");
var referee = require("./referee");

describe("add", function() {
Expand Down Expand Up @@ -130,4 +131,30 @@ describe("add", function() {
assert(error instanceof TypeError);
});
});

context("with assert returning a promise", function() {
before(function() {
if (typeof Promise === "undefined") {
this.skip();
}
});

it("returns a promise and calls referee.pass when resolved", function() {
var then = sinon.fake();
var options = {
assert: function(thing) {
return thing && new Promise(then);
},
assertMessage: "returning a promise",
refuteMessage: "not returning a promise"
};
referee.add("returningPromise", options);

var result = referee.assert.returningPromise(1);

assert(result instanceof Promise);

then.firstCall.args[0](); // Get coverage on then handler
});
});
});

0 comments on commit a02ff67

Please sign in to comment.