Skip to content

Commit

Permalink
add message defaults to .ok() and .notOk()
Browse files Browse the repository at this point in the history
  • Loading branch information
paulcpederson committed Mar 25, 2016
1 parent 5060034 commit 91b639c
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 9 deletions.
4 changes: 2 additions & 2 deletions lib/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ Test.prototype.ok
= Test.prototype.assert
= function (value, msg, extra) {
this._assert(value, {
message : msg,
message : defined(msg, 'should be truthy'),
operator : 'ok',
expected : true,
actual : value,
Expand All @@ -315,7 +315,7 @@ Test.prototype.notOk
= Test.prototype.notok
= function (value, msg, extra) {
this._assert(!value, {
message : msg,
message : defined(msg, 'should be falsy'),
operator : 'notOk',
expected : false,
actual : value,
Expand Down
37 changes: 37 additions & 0 deletions test/default-messages.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
var tap = require('tap');
var spawn = require('child_process').spawn;
var trim = require('string.prototype.trim');

tap.test('default messages', function (t) {
t.plan(1);

var tc = tap.createConsumer();

var rows = [];
tc.on('data', function (r) { rows.push(r) });
tc.on('end', function () {
var rs = rows.map(function (r) {
if (r && typeof r === 'object') {
return { id : r.id, ok : r.ok, name : trim(r.name) };
}
else return r;
});
t.same(rs, [
'TAP version 13',
'default messages',
{ id: 1, ok: true, name: 'should be truthy' },
{ id: 2, ok: true, name: 'should be falsy' },
{ id: 3, ok: true, name: 'should be equal' },
{ id: 4, ok: true, name: 'should not be equal' },
{ id: 5, ok: true, name: 'should be equivalent' },
{ id: 6, ok: true, name: 'should be equivalent' },
{ id: 7, ok: true, name: 'should be equivalent' },
'tests 7',
'pass 7',
'ok'
]);
});

var ps = spawn(process.execPath, [ __dirname + '/messages/defaults.js' ]);
ps.stdout.pipe(tc);
});
4 changes: 2 additions & 2 deletions test/exit.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ tap.test('more planned in a second test', function (t) {
t.same(rs, [
'TAP version 13',
'first',
{ id: 1, ok: true, name: '(unnamed assert)' },
{ id: 1, ok: true, name: 'should be truthy' },
'second',
{ id: 2, ok: true, name: '(unnamed assert)' },
{ id: 2, ok: true, name: 'should be truthy' },
{ id: 3, ok: false, name: 'plan != count' },
'tests 3',
'pass 2',
Expand Down
12 changes: 12 additions & 0 deletions test/messages/defaults.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
var test = require('../../');

test('default messages', function (t) {
t.plan(7);
t.ok(true);
t.notOk(false);
t.equal(true, true);
t.notEqual(true, false);
t.deepEqual(true, true);
t.deepLooseEqual(true, true);
t.notDeepLooseEqual(true, false);
});
4 changes: 2 additions & 2 deletions test/nested-sync-noplan-noend.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ tap.test('nested sync test without plan or end', function (tt) {
'TAP version 13',
'nested without plan or end',
'first',
{ id: 1, ok: true, name: '(unnamed assert)' },
{ id: 1, ok: true, name: 'should be truthy' },
'second',
{ id: 2, ok: true, name: '(unnamed assert)' },
{ id: 2, ok: true, name: 'should be truthy' },
'tests 2',
'pass 2',
'ok'
Expand Down
6 changes: 3 additions & 3 deletions test/nested.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ tap.test('array test', function (tt) {
{ id: 4, ok: true, name: 'should be equivalent' },
{ id: 5, ok: true, name: 'should be equivalent' },
'inside test',
{ id: 6, ok: true, name: '(unnamed assert)' },
{ id: 7, ok: true, name: '(unnamed assert)' },
{ id: 6, ok: true, name: 'should be truthy' },
{ id: 7, ok: true, name: 'should be truthy' },
'another',
{ id: 8, ok: true, name: '(unnamed assert)' },
{ id: 8, ok: true, name: 'should be truthy' },
'tests 8',
'pass 8',
'ok'
Expand Down

0 comments on commit 91b639c

Please sign in to comment.