Skip to content

Commit 3651241

Browse files
committed
Follow-up to #831 (#835)
* change failing test hint * mark .failing as code in readme * group and reword failing tests The tests are better when grouped together. I tried to give them more consistent titles too. * remove spurious trailing space in t.end error message
1 parent 0410a03 commit 3651241

File tree

3 files changed

+49
-51
lines changed

3 files changed

+49
-51
lines changed

lib/test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ Test.prototype._result = function () {
191191
if (this.metadata.failing) {
192192
passed = !passed;
193193
if (!passed) {
194-
reason = new Error('Test was expected to fail, but succeeded, you should unmark the test as failing');
194+
reason = new Error('Test was expected to fail, but succeeded, you should stop marking the test as failing');
195195
}
196196
}
197197
return {passed: passed, result: this, reason: reason};
@@ -203,7 +203,7 @@ Object.defineProperty(Test.prototype, 'end', {
203203
return this._end.bind(this);
204204
}
205205

206-
throw new Error('t.end is not supported in this context. To use t.end as a callback, you must use "callback mode" via `test.cb(testName, fn)` ');
206+
throw new Error('t.end is not supported in this context. To use t.end as a callback, you must use "callback mode" via `test.cb(testName, fn)`');
207207
}
208208
});
209209

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ test.todo('will think about writing this later');
417417

418418
### Failing tests
419419

420-
You can use the `.failing` modifier to document issues with your code that need to be fixed. Failing tests are run just like normal ones, but they are expected to fail, and will not break your build when they do. If a test marked as failing actually passes, it will be reported as an error and fail the build with a helpful message instructing you to remove the .failing modifier.
420+
You can use the `.failing` modifier to document issues with your code that need to be fixed. Failing tests are run just like normal ones, but they are expected to fail, and will not break your build when they do. If a test marked as failing actually passes, it will be reported as an error and fail the build with a helpful message instructing you to remove the `.failing` modifier.
421421

422422
This allows you to merge `.failing` tests before a fix is implemented without breaking CI. This is a great way to recognize good bug report PR's with a commit credit, even if the reporter is unable to actually fix the problem.
423423

test/test.js

Lines changed: 46 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ var delay = require('delay');
55
var isPromise = require('is-promise');
66
var Test = require('../lib/test');
77

8-
var failingTestHint = 'Test was expected to fail, but succeeded, you should unmark the test as failing';
8+
var failingTestHint = 'Test was expected to fail, but succeeded, you should stop marking the test as failing';
99

1010
function ava(title, fn, contextRef, report) {
1111
var t = new Test(title, fn, contextRef, report);
@@ -48,25 +48,6 @@ test('run test', function (t) {
4848
t.end();
4949
});
5050

51-
test('expected failing test', function (t) {
52-
var result = ava.failing('foo', function (a) {
53-
a.fail();
54-
}).run();
55-
56-
t.is(result.passed, true);
57-
t.end();
58-
});
59-
60-
test('fail a failing test if it pass', function (t) {
61-
var result = ava.failing('foo', function (a) {
62-
a.pass();
63-
}).run();
64-
65-
t.is(result.passed, false);
66-
t.is(result.reason.message, failingTestHint);
67-
t.end();
68-
});
69-
7051
test('title is optional', function (t) {
7152
var result = ava(function (a) {
7253
a.pass();
@@ -171,27 +152,6 @@ test('end can be used as callback with error', function (t) {
171152
});
172153
});
173154

174-
test('fail a failing callback test if it passed', function (t) {
175-
ava.cb.failing(function (a) {
176-
a.end();
177-
}).run().then(function (result) {
178-
t.is(result.passed, false);
179-
t.is(result.reason.message, failingTestHint);
180-
t.end();
181-
});
182-
});
183-
184-
test('failing can work with callback', function (t) {
185-
var err = new Error('failed');
186-
ava.cb.failing(function (a) {
187-
a.end(err);
188-
}).run().then(function (result) {
189-
t.is(result.passed, true);
190-
t.is(result.reason, err);
191-
t.end();
192-
});
193-
});
194-
195155
test('end can be used as callback with a non-error as its error argument', function (t) {
196156
var nonError = {foo: 'bar'};
197157
ava.cb(function (a) {
@@ -642,10 +602,48 @@ test('it is an error to set context in a hook', function (t) {
642602
t.end();
643603
});
644604

645-
test('failing test returns a resolved promise is failure', function (t) {
646-
ava.failing(function (a) {
647-
a.plan(1);
648-
a.notThrows(delay(10), 'foo');
605+
test('failing tests should fail', function (t) {
606+
var result = ava.failing('foo', function (a) {
607+
a.fail();
608+
}).run();
609+
610+
t.is(result.passed, true);
611+
t.end();
612+
});
613+
614+
test('failing callback tests should end with an error', function (t) {
615+
var err = new Error('failed');
616+
ava.cb.failing(function (a) {
617+
a.end(err);
618+
}).run().then(function (result) {
619+
t.is(result.passed, true);
620+
t.is(result.reason, err);
621+
t.end();
622+
});
623+
});
624+
625+
test('failing tests must not pass', function (t) {
626+
var result = ava.failing('foo', function (a) {
627+
a.pass();
628+
}).run();
629+
630+
t.is(result.passed, false);
631+
t.is(result.reason.message, failingTestHint);
632+
t.end();
633+
});
634+
635+
test('failing callback tests must not pass', function (t) {
636+
ava.cb.failing(function (a) {
637+
a.end();
638+
}).run().then(function (result) {
639+
t.is(result.passed, false);
640+
t.is(result.reason.message, failingTestHint);
641+
t.end();
642+
});
643+
});
644+
645+
test('failing tests must not return a fulfilled promise', function (t) {
646+
ava.failing(function () {
649647
return Promise.resolve();
650648
}).run().then(function (result) {
651649
t.is(result.passed, false);
@@ -654,7 +652,7 @@ test('failing test returns a resolved promise is failure', function (t) {
654652
});
655653
});
656654

657-
test('failing test returns a rejected promise is passing', function (t) {
655+
test('failing tests pass when returning a rejected promise', function (t) {
658656
ava.failing(function (a) {
659657
a.plan(1);
660658
a.notThrows(delay(10), 'foo');
@@ -665,7 +663,7 @@ test('failing test returns a rejected promise is passing', function (t) {
665663
});
666664
});
667665

668-
test('failing test with t.throws(nonThrowingPromise) is passing', function (t) {
666+
test('failing tests pass with `t.throws(nonThrowingPromise)`', function (t) {
669667
ava.failing(function (a) {
670668
a.throws(Promise.resolve(10));
671669
}).run().then(function (result) {
@@ -674,7 +672,7 @@ test('failing test with t.throws(nonThrowingPromise) is passing', function (t) {
674672
});
675673
});
676674

677-
test('failing test with t.notThrows(throws) is failure', function (t) {
675+
test('failing tests fail with `t.notThrows(throws)`', function (t) {
678676
ava.failing(function (a) {
679677
a.notThrows(Promise.resolve('foo'));
680678
}).run().then(function (result) {

0 commit comments

Comments
 (0)