Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make t.log() behave like console.log() #1653

Merged
merged 5 commits into from
Jan 25, 2018

Conversation

kugtong33
Copy link
Contributor

Fixes #1635

Use concordance to format all arguments except string arguments as the existing test will fail and I find it awkward this way. Update test to cater t.log() and t.log(n1, n2, n3, ...).

Copy link
Member

@novemberborn novemberborn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

console.log() uses util.format() underneath, which supports placeholder tokens. I couldn't quite find a maintained & ready module that would let us support the same tokens. Perhaps we can leave that as a follow-up.

lib/assert.js Outdated
@@ -122,8 +122,15 @@ function wrapAssertions(callbacks) {
}
},

log(text) {
log(this, text);
log(...args) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the next few months we're still targeting Node.js 4, which doesn't support rest parameters. You'll have to use plain old arguments instead.

lib/assert.js Outdated
args.forEach((value, index) => {
args[index] = typeof value === 'string' ?
value : concordance.format(value, concordanceOptions);
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you're really mapping args anyway this would be better as:

const args = Array.from(arguments, value => {
  // ...
});

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that makes sense! I was trying to find a better way :)

@sindresorhus sindresorhus changed the title Let t.log behaves like console.log Make t.log() behave like console.log() Jan 25, 2018
@novemberborn novemberborn merged commit 4f896c2 into avajs:master Jan 25, 2018
@novemberborn
Copy link
Member

Thanks @kugtong33!

@kugtong33 kugtong33 deleted the assert-log-revamp branch February 14, 2018 10:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make t.log() behave like console.log()
2 participants