Skip to content

Commit

Permalink
Tests: Add case for assert.throws() matching
Browse files Browse the repository at this point in the history
Ref #1333.
  • Loading branch information
Krinkle committed Dec 15, 2018
1 parent b520839 commit 0b6444c
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
17 changes: 17 additions & 0 deletions test/cli/fixtures/expected/tap-outputs.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,23 @@ ok 2 Second > 1
# todo 0
# fail 0`,

"qunit 'fail/throws-match.js'":
`TAP version 13
not ok 1 global failure
---
message: "match error"
severity: failed
actual: {}
expected: {}
stack: .*
...
1..1
# pass 0
# skip 0
# todo 0
# fail 1
`,

"qunit test single.js 'glob/**/*-test.js'":
`TAP version 13
ok 1 A-Test > derp
Expand Down
7 changes: 7 additions & 0 deletions test/cli/fixtures/fail/throws-match.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
QUnit.module( "Throws match", function() {
QUnit.test( "bad", function( assert ) {
assert.throws( function() {
throw new Error( "Match me with a pattern" );
}, /incorrect pattern/, "match error" );
} );
} );
14 changes: 13 additions & 1 deletion test/cli/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,21 @@ QUnit.module( "CLI Main", function() {
}
} ) );

QUnit.test( "report assert.throws() failures properly", co.wrap( function* ( assert ) {
const command = "qunit fail/throws-match.js";
try {
yield execute( command );
} catch ( e ) {
assert.equal( e.code, 1 );
assert.equal( e.stderr, "" );
const re = new RegExp( expectedOutput[ command ] );
assert.equal( re.test( e.stdout ), true );
}
} ) );

QUnit.test( "exit code is 1 when failing tests are present", co.wrap( function* ( assert ) {
try {
yield execute( "qunit fail/*.js" );
yield execute( "qunit fail/failure.js" );
} catch ( e ) {
assert.equal( e.code, 1 );
}
Expand Down

0 comments on commit 0b6444c

Please sign in to comment.