Skip to content

Commit

Permalink
Added alias throw to throwException/throwError
Browse files Browse the repository at this point in the history
  • Loading branch information
janmarek committed Jan 18, 2015
1 parent 304a246 commit 688c456
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,10 @@ expect({ a: 'b', c: 'd' }).to.only.have.keys(['a', 'c']);
expect({ a: 'b', c: 'd' }).to.not.only.have.key('a');
```

**throwException**/**throwError**: asserts that the `Function` throws or not when called
**throw**/**throwException**/**throwError**: asserts that the `Function` throws or not when called

```js
expect(fn).to.throw(); // synonym of throwException
expect(fn).to.throwError(); // synonym of throwException
expect(fn).to.throwException(function (e) { // get the exception object
expect(e).to.be.a(SyntaxError);
Expand Down Expand Up @@ -207,7 +208,7 @@ and shown/processed by the test runner.

## Differences with should.js

- No need for static `should` methods like `should.strictEqual`. For example,
- No need for static `should` methods like `should.strictEqual`. For example,
`expect(obj).to.be(undefined)` works well.
- Some API simplifications / changes.
- API changes related to browser compatibility.
Expand Down
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@
* @api public
*/

Assertion.prototype['throw'] =
Assertion.prototype.throwError =
Assertion.prototype.throwException = function (fn) {
expect(this.obj).to.be.a('function');
Expand Down Expand Up @@ -637,7 +638,7 @@
if (isDate(value) && $keys.length === 0) {
return stylize(value.toUTCString(), 'date');
}

// Error objects can be shortcutted
if (value instanceof Error) {
return stylize("["+value.toString()+"]", 'Error');
Expand Down
12 changes: 10 additions & 2 deletions test/expect.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,14 @@ describe('expect', function () {

expect(called).to.be(false);

var called2 = false;

expect(itWorks).to.not.throw(function () {
called2 = true;
});

expect(called2).to.be(false);

err(function () {
expect(5).to.throwException();
}, 'expected 5 to be a function');
Expand Down Expand Up @@ -382,7 +390,7 @@ describe('expect', function () {
err(function () {
expect('asd').to.have.property('foo');
}, "expected 'asd' to have a property 'foo'");

err(function () {
expect({ length: undefined }).to.not.have.property('length');
}, "expected { length: undefined } to not have a property 'length'");
Expand All @@ -403,7 +411,7 @@ describe('expect', function () {
err(function () {
expect('asd').to.not.have.property('foo', 3);
}, "'asd' has no property 'foo'");

err(function () {
expect({ length: undefined }).to.not.have.property('length', undefined);
}, "expected { length: undefined } to not have a property 'length'");
Expand Down

0 comments on commit 688c456

Please sign in to comment.