Skip to content

Commit 3857c31

Browse files
committed
Tests: Add case for errors while console is mocked
The asserted output is not what we'd like it to be. This is just to document what happens today. Ref #1340.
1 parent b54e732 commit 3857c31

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

test/cli/fixtures/expected/tap-outputs.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,16 @@ not ok 1 global failure
6767
# skip 0
6868
# todo 0
6969
# fail 1
70+
`,
71+
72+
"qunit 'fail/mocked-console.js'":
73+
`TAP version 13
74+
ok 2 Uncaught error > good
75+
1..2
76+
# pass 1
77+
# skip 0
78+
# todo 0
79+
# fail 1
7080
`,
7181

7282
"qunit test single.js 'glob/**/*-test.js'":
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
QUnit.module( "Error with mocked console", function( hooks ) {
2+
var orgLog, orgError;
3+
4+
// Stub
5+
hooks.before( function() {
6+
orgLog = console.log;
7+
orgError = console.error;
8+
console.log = console.error = function() {};
9+
} );
10+
11+
// Restore
12+
hooks.after( function() {
13+
console.log = orgLog;
14+
console.error = orgError;
15+
} );
16+
17+
QUnit.test( "bad", function( assert ) {
18+
assert.ok( this.aint() );
19+
} );
20+
21+
QUnit.test( "good", function( assert ) {
22+
assert.ok( 1 );
23+
} );
24+
} );

test/cli/main.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ QUnit.module( "CLI Main", function() {
7979
}
8080
} ) );
8181

82+
// Test case for https://github.com/qunitjs/qunit/issues/1333
8283
QUnit.test( "report assert.throws() failures properly", co.wrap( function* ( assert ) {
8384
const command = "qunit fail/throws-match.js";
8485
try {
@@ -91,6 +92,19 @@ QUnit.module( "CLI Main", function() {
9192
}
9293
} ) );
9394

95+
// Test case for https://github.com/qunitjs/qunit/issues/1340
96+
QUnit.test( "report errors with mocked console", co.wrap( function* ( assert ) {
97+
const command = "qunit fail/mocked-console.js";
98+
try {
99+
yield execute( command );
100+
} catch ( e ) {
101+
assert.equal( e.code, 1 );
102+
assert.equal( e.stderr, "" );
103+
const re = new RegExp( expectedOutput[ command ] );
104+
assert.equal( re.test( e.stdout ), true );
105+
}
106+
} ) );
107+
94108
QUnit.test( "exit code is 1 when failing tests are present", co.wrap( function* ( assert ) {
95109
try {
96110
yield execute( "qunit fail/failure.js" );

0 commit comments

Comments
 (0)