Skip to content

Commit 1214212

Browse files
committed
Let t.log behaves like console.log
1 parent bcb77fc commit 1214212

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

lib/assert.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,15 @@ function wrapAssertions(callbacks) {
122122
}
123123
},
124124

125-
log(text) {
126-
log(this, text);
125+
log(...args) {
126+
args.forEach((value, index) => {
127+
args[index] = typeof value === 'string' ?
128+
value : concordance.format(value, concordanceOptions);
129+
});
130+
131+
if (args.length > 0) {
132+
log(this, args.join(' '));
133+
}
127134
},
128135

129136
deepEqual(actual, expected, message) {

test/test.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -741,13 +741,19 @@ test('log from tests', t => {
741741
a.log('a log message from a test');
742742
t.true(true);
743743
a.log('another log message from a test');
744+
a.log({b: 1, c: {d: 2}}, 'complex log', 5, 5.1);
745+
t.log();
744746
}, null, r => {
745747
result = r;
746748
}).run();
747749

748750
t.deepEqual(
749751
result.result.logs,
750-
['a log message from a test', 'another log message from a test']
752+
[
753+
'a log message from a test',
754+
'another log message from a test',
755+
'{\n b: 1,\n c: {\n d: 2,\n },\n} complex log 5 5.1'
756+
]
751757
);
752758

753759
t.end();

0 commit comments

Comments
 (0)