Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #20 from yourcelf/master

Add explicit failure through `expect().fail()`
  • Loading branch information...
commit 9aa632fb2f16784fbfe050eef08d60596e649229 2 parents 654c8dd + 64913e6
@rauchg rauchg authored
Showing with 30 additions and 0 deletions.
  1. +7 −0 README.md
  2. +11 −0 expect.js
  3. +12 −0 test/expect.js
View
7 README.md
@@ -162,6 +162,13 @@ expect(0).to.be.below(3);
expect(1).to.be.lessThan(3);
```
+**fail**: explicitly forces failure.
+
+```js
+expect().fail()
+expect().fail("Custom failure message")
+```
+
## Using with a test framework
For example, if you create a test suite with
View
11 expect.js
@@ -459,6 +459,17 @@
return this;
};
+ /**
+ * Assert a failure.
+ *
+ * @param {String ...} custom message
+ * @api public
+ */
+ Assertion.prototype.fail = function (msg) {
+ msg = msg || "explicit failure";
+ this.assert(false, msg, msg);
+ return this;
+ };
/**
* Function bind implementation.
View
12 test/expect.js
@@ -527,4 +527,16 @@ describe('expect', function () {
}, "expected 5 to be below 4");
});
+ it('should fail with `fail`', function () {
+ err(function () {
+ expect().fail();
+ }, "explicit failure");
+ });
+
+ it('should fail with `fail` and custom message', function () {
+ err(function () {
+ expect().fail("explicit failure with message");
+ }, "explicit failure with message");
+ });
+
});
Please sign in to comment.
Something went wrong with that request. Please try again.