Skip to content

Commit 549e99b

Browse files
committed
Document t.title accessor
Clean up tests which unnecessarily use the accessor, and add a single dedicated test instead.
1 parent ec94f94 commit 549e99b

File tree

4 files changed

+26
-66
lines changed

4 files changed

+26
-66
lines changed

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -867,7 +867,7 @@ Should contain the actual test.
867867

868868
Type: `object`
869869

870-
The execution object of a particular test. Each test implementation receives a different object. Contains the [assertions](#assertions) as well as `.plan(count)` and `.end()` methods. `t.context` can contain shared state from `beforeEach` hooks.
870+
The execution object of a particular test. Each test implementation receives a different object. Contains the [assertions](#assertions) as well as `.plan(count)` and `.end()` methods. `t.context` can contain shared state from `beforeEach` hooks. `t.title` returns the test's title.
871871

872872
###### `t.plan(count)`
873873

test/runner.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,6 @@ test('macros: Customize test names attaching a `title` function', t => {
745745
];
746746

747747
function macroFn(avaT) {
748-
t.is(avaT.title, expectedTitles.shift());
749748
t.deepEqual(slice.call(arguments, 1), expectedArgs.shift());
750749
avaT.pass();
751750
}
@@ -754,6 +753,10 @@ test('macros: Customize test names attaching a `title` function', t => {
754753

755754
const runner = new Runner();
756755

756+
runner.on('test', props => {
757+
t.is(props.title, expectedTitles.shift());
758+
});
759+
757760
runner.chain.test(macroFn, 'A');
758761
runner.chain.test('supplied', macroFn, 'B');
759762
runner.chain.test(macroFn, 'C');
@@ -770,7 +773,6 @@ test('match applies to macros', t => {
770773
t.plan(3);
771774

772775
function macroFn(avaT) {
773-
t.is(avaT.title, 'foobar');
774776
avaT.pass();
775777
}
776778

@@ -780,6 +782,10 @@ test('match applies to macros', t => {
780782
match: ['foobar']
781783
});
782784

785+
runner.on('test', props => {
786+
t.is(props.title, 'foobar');
787+
});
788+
783789
runner.chain.test(macroFn, 'foo');
784790
runner.chain.test(macroFn, 'bar');
785791

@@ -842,7 +848,6 @@ test('match applies to arrays of macros', t => {
842848
fooMacro.title = (title, firstArg) => `${firstArg}foo`;
843849

844850
function barMacro(avaT) {
845-
t.is(avaT.title, 'foobar');
846851
avaT.pass();
847852
}
848853
barMacro.title = (title, firstArg) => `${firstArg}bar`;
@@ -857,6 +862,10 @@ test('match applies to arrays of macros', t => {
857862
match: ['foobar']
858863
});
859864

865+
runner.on('test', props => {
866+
t.is(props.title, 'foobar');
867+
});
868+
860869
runner.chain.test([fooMacro, barMacro, bazMacro], 'foo');
861870
runner.chain.test([fooMacro, barMacro, bazMacro], 'bar');
862871

test/test-collection.js

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -239,68 +239,6 @@ test('adding a bunch of different types', t => {
239239
t.end();
240240
});
241241

242-
test('foo', t => {
243-
const collection = new TestCollection({});
244-
const log = [];
245-
246-
function logger(a) {
247-
log.push(a.title);
248-
a.pass();
249-
}
250-
251-
function add(title, opts) {
252-
collection.add({
253-
title,
254-
metadata: metadata(opts),
255-
fn: logger
256-
});
257-
}
258-
259-
add('after1', {type: 'after'});
260-
add('after.always', {
261-
type: 'after',
262-
always: true
263-
});
264-
add('beforeEach1', {type: 'beforeEach'});
265-
add('before1', {type: 'before'});
266-
add('beforeEach2', {type: 'beforeEach'});
267-
add('afterEach1', {type: 'afterEach'});
268-
add('afterEach.always', {
269-
type: 'afterEach',
270-
always: true
271-
});
272-
add('test1', {});
273-
add('afterEach2', {type: 'afterEach'});
274-
add('test2', {});
275-
add('after2', {type: 'after'});
276-
add('before2', {type: 'before'});
277-
278-
const passed = collection.build().run();
279-
t.is(passed, true);
280-
281-
t.strictDeepEqual(log, [
282-
'before1',
283-
'before2',
284-
'beforeEach1 for test1',
285-
'beforeEach2 for test1',
286-
'test1',
287-
'afterEach1 for test1',
288-
'afterEach2 for test1',
289-
'afterEach.always for test1',
290-
'beforeEach1 for test2',
291-
'beforeEach2 for test2',
292-
'test2',
293-
'afterEach1 for test2',
294-
'afterEach2 for test2',
295-
'afterEach.always for test2',
296-
'after1',
297-
'after2',
298-
'after.always'
299-
]);
300-
301-
t.end();
302-
});
303-
304242
test('foo', t => {
305243
const collection = new TestCollection({});
306244
const log = [];

test/test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,19 @@ test('end can be used as callback with a non-error as its error argument', t =>
199199
t.end();
200200
});
201201

202+
test('title returns the test title', t => {
203+
t.plan(1);
204+
new Test({
205+
fn(a) {
206+
t.is(a.title, 'foo');
207+
a.pass();
208+
},
209+
metadata: {type: 'test', callback: false},
210+
onResult: noop,
211+
title: 'foo'
212+
}).run();
213+
});
214+
202215
test('handle non-assertion errors even when planned', t => {
203216
const err = new Error('bar');
204217
let result;

0 commit comments

Comments
 (0)