Skip to content

Commit 2b6b256

Browse files
author
Vadim Demedes
committed
Merge pull request #331 from sotojuan/tap-match
Use `t.match` instead of `t.true` in tests
2 parents ad7ae19 + 7030c66 commit 2b6b256

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

test/api.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ test('fail-fast mode', function (t) {
6666
t.ok(api.options.failFast);
6767
t.is(api.passCount, 1);
6868
t.is(api.failCount, 1);
69-
t.true(/Test failed via t.fail()/.test(api.errors[0].error.message));
69+
t.match(api.errors[0].error.message, /Test failed via t.fail()/);
7070
});
7171
});
7272

@@ -92,7 +92,7 @@ test('circular references on assertions do not break process.send', function (t)
9292
api.run()
9393
.then(function () {
9494
t.is(api.failCount, 1);
95-
t.true(/'c'.*?'d'/.test(api.errors[0].error.message));
95+
t.match(api.errors[0].error.message, /'c'.*?'d'/);
9696
});
9797
});
9898

@@ -114,7 +114,7 @@ test('unhandled promises will throw an error', function (t) {
114114

115115
api.on('error', function (data) {
116116
t.is(data.name, 'Error');
117-
t.true(/You can\'t handle this!/.test(data.message));
117+
t.match(data.message, /You can\'t handle this!/);
118118
});
119119

120120
api.run()
@@ -130,7 +130,7 @@ test('uncaught exception will throw an error', function (t) {
130130

131131
api.on('error', function (data) {
132132
t.is(data.name, 'Error');
133-
t.true(/Can\'t catch me!/.test(data.message));
133+
t.match(data.message, /Can\'t catch me!/);
134134
});
135135

136136
api.run()
@@ -145,7 +145,7 @@ test('stack traces for exceptions are corrected using a source map file', functi
145145
var api = new Api([path.join(__dirname, 'fixture/source-map-file.js')]);
146146

147147
api.on('error', function (data) {
148-
t.true(/Thrown by source-map-fixtures/.test(data.message));
148+
t.match(data.message, /Thrown by source-map-fixtures/);
149149
t.match(data.stack, /^.*?at.*?run\b.*source-map-fixtures.src.throws.js:1.*$/m);
150150
t.match(data.stack, /^.*?at\b.*source-map-file.js:11.*$/m);
151151
});
@@ -162,7 +162,7 @@ test('stack traces for exceptions are corrected using a source map, taking an in
162162
var api = new Api([path.join(__dirname, 'fixture/source-map-initial.js')]);
163163

164164
api.on('error', function (data) {
165-
t.true(/Thrown by source-map-fixtures/.test(data.message));
165+
t.match(data.message, /Thrown by source-map-fixtures/);
166166
t.match(data.stack, /^.*?at.*?run\b.*source-map-fixtures.src.throws.js:1.*$/m);
167167
t.match(data.stack, /^.*?at\b.*source-map-initial-input.js:7.*$/m);
168168
});
@@ -191,9 +191,9 @@ test('titles of both passing and failing tests and AssertionErrors are returned'
191191

192192
api.run()
193193
.then(function () {
194-
t.true(/this is a failing test/.test(api.errors[0].title));
195-
t.true(/this is a passing test/.test(api.tests[0].title));
196-
t.true(/AssertionError/.test(api.errors[0].error.name));
194+
t.match(api.errors[0].title, /this is a failing test/);
195+
t.match(api.tests[0].title, /this is a passing test/);
196+
t.match(api.errors[0].error.name, /AssertionError/);
197197
});
198198
});
199199

@@ -205,7 +205,7 @@ test('empty test files creates a failure with a helpful warning', function (t) {
205205
api.run()
206206
.catch(function (err) {
207207
t.ok(err);
208-
t.true(/No tests found.*?import "ava"/.test(err.message));
208+
t.match(err.message, /No tests found.*?import "ava"/);
209209
});
210210
});
211211

@@ -217,7 +217,7 @@ test('test file with no tests creates a failure with a helpful warning', functio
217217
api.run()
218218
.catch(function (err) {
219219
t.ok(err);
220-
t.true(/No tests/.test(err.message));
220+
t.match(err.message, /No tests/);
221221
});
222222
});
223223

@@ -229,7 +229,7 @@ test('test file that immediately exits with 0 exit code ', function (t) {
229229
api.run()
230230
.catch(function (err) {
231231
t.ok(err);
232-
t.true(/Test results were not received from/.test(err.message));
232+
t.match(err.message, /Test results were not received from/);
233233
});
234234
});
235235

@@ -253,7 +253,7 @@ test('test file in node_modules is ignored', function (t) {
253253
api.run()
254254
.catch(function (err) {
255255
t.ok(err);
256-
t.true(/Couldn't find any files to test/.test(err.message));
256+
t.match(err.message, /Couldn't find any files to test/);
257257
});
258258
});
259259

test/cli.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ test('don\'t display test title if there is only one anonymous test', function (
7777
test('throwing a named function will report the to the console', function (t) {
7878
execCli('fixture/throw-named-function.js', function (err, stdout, stderr) {
7979
t.ok(err);
80-
t.true(/\[Function: fooFn]/.test(stderr));
80+
t.match(stderr, /\[Function: fooFn]/);
8181
// TODO(jamestalmage)
8282
// t.ok(/1 uncaught exception[^s]/.test(stdout));
8383
t.end();
@@ -98,7 +98,7 @@ test('babel require hook only applies to the test file', function (t) {
9898
test('throwing a anonymous function will report the function to the console', function (t) {
9999
execCli('fixture/throw-anonymous-function.js', function (err, stdout, stderr) {
100100
t.ok(err);
101-
t.true(/\[Function: anonymous]/.test(stderr));
101+
t.match(stderr, /\[Function: anonymous]/);
102102
// TODO(jamestalmage)
103103
// t.ok(/1 uncaught exception[^s]/.test(stdout));
104104
t.end();

0 commit comments

Comments
 (0)