Skip to content

Commit 9f0efa2

Browse files
committed
Merge pull request #122 from janmarek/throw-alias
Added alias throw to throwException/throwError
2 parents 304a246 + 688c456 commit 9f0efa2

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,10 @@ expect({ a: 'b', c: 'd' }).to.only.have.keys(['a', 'c']);
130130
expect({ a: 'b', c: 'd' }).to.not.only.have.key('a');
131131
```
132132

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

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

208209
## Differences with should.js
209210

210-
- No need for static `should` methods like `should.strictEqual`. For example,
211+
- No need for static `should` methods like `should.strictEqual`. For example,
211212
`expect(obj).to.be(undefined)` works well.
212213
- Some API simplifications / changes.
213214
- API changes related to browser compatibility.

index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@
138138
* @api public
139139
*/
140140

141+
Assertion.prototype['throw'] =
141142
Assertion.prototype.throwError =
142143
Assertion.prototype.throwException = function (fn) {
143144
expect(this.obj).to.be.a('function');
@@ -637,7 +638,7 @@
637638
if (isDate(value) && $keys.length === 0) {
638639
return stylize(value.toUTCString(), 'date');
639640
}
640-
641+
641642
// Error objects can be shortcutted
642643
if (value instanceof Error) {
643644
return stylize("["+value.toString()+"]", 'Error');

test/expect.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,14 @@ describe('expect', function () {
156156

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

159+
var called2 = false;
160+
161+
expect(itWorks).to.not.throw(function () {
162+
called2 = true;
163+
});
164+
165+
expect(called2).to.be(false);
166+
159167
err(function () {
160168
expect(5).to.throwException();
161169
}, 'expected 5 to be a function');
@@ -382,7 +390,7 @@ describe('expect', function () {
382390
err(function () {
383391
expect('asd').to.have.property('foo');
384392
}, "expected 'asd' to have a property 'foo'");
385-
393+
386394
err(function () {
387395
expect({ length: undefined }).to.not.have.property('length');
388396
}, "expected { length: undefined } to not have a property 'length'");
@@ -403,7 +411,7 @@ describe('expect', function () {
403411
err(function () {
404412
expect('asd').to.not.have.property('foo', 3);
405413
}, "'asd' has no property 'foo'");
406-
414+
407415
err(function () {
408416
expect({ length: undefined }).to.not.have.property('length', undefined);
409417
}, "expected { length: undefined } to not have a property 'length'");

0 commit comments

Comments
 (0)