Skip to content

Commit

Permalink
make t.throws match if regex is passed
Browse files Browse the repository at this point in the history
  • Loading branch information
evanlucas committed Nov 11, 2015
1 parent 5a61d16 commit 5152834
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,12 @@ function decorate (t) {
// 'name' is a getter.
if (er.name)
er.name = er.name + ''
if (wanted)
if (wanted) {
if (Object.prototype.toString.call(wanted) === '[object RegExp]') {
return this.match(er.message, wanted, m, e)
}
return this.has(er, wanted, m, e)
}
else
return this.pass(m, e)
}
Expand Down
11 changes: 11 additions & 0 deletions test/test/throws-bail.tap
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
TAP version 13
# Subtest: throws should match a regex
1..2
ok 1 - expected to throw
not ok 2 - expected to throw
---
{"at":{"column":5,"file":"test/test/throws.js","line":9},"found":"test","pattern":"/fasdfsadf/","source":"t.throws(function() {\n"}
...
Bail out! # expected to throw
Bail out! # expected to throw

12 changes: 12 additions & 0 deletions test/test/throws.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
var t = require('../..')

t.test('throws should match a regex', function(t) {
t.plan(2)
t.throws(function() {
throw new Error('test')
}, /test/)

t.throws(function() {
throw new Error('test')
}, /fasdfsadf/)
})
18 changes: 18 additions & 0 deletions test/test/throws.tap
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
TAP version 13
# Subtest: throws should match a regex
1..2
ok 1 - expected to throw
not ok 2 - expected to throw
---
{"at":{"column":5,"file":"test/test/throws.js","line":9},"found":"test","pattern":"/fasdfsadf/","source":"t.throws(function() {\n"}
...
# failed 1 of 2 tests
not ok 1 - throws should match a regex ___/# time=[0-9.]+(ms)?/~~~
---
{"at":{"column":3,"file":"test/test/throws.js","line":3},"results":{"count":2,"fail":1,"ok":false,"pass":1,"plan":{"end":2,"start":1}},"source":"t.test('throws should match a regex', function(t) {\n"}
...

1..1
# failed 1 of 1 tests
___/# time=[0-9.]+(ms)?/~~~

0 comments on commit 5152834

Please sign in to comment.