Skip to content

Allow multiple message arguments in assertions? #1748

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

Closed
billyjanitsch opened this issue Mar 21, 2018 · 2 comments
Closed

Allow multiple message arguments in assertions? #1748

billyjanitsch opened this issue Mar 21, 2018 · 2 comments

Comments

@billyjanitsch
Copy link
Contributor

Description

I've found t.log extremely useful, especially in how it formats React elements and test renderer output. I often write code like:

t.log(actualComponent, 'did not match', expectedComponent)

Unfortunately there's no way to pass this sort of message to an actual assertion, since they only take a single message argument. If I use a template string (${actualComponent} did not match ${expectedComponent}) then I lose AVA's fancy formatting. I have to choose between passing a string or a single object to be nicely formatted.

This seems like a pretty limiting restriction. I wish I could do stuff like:

t.notThrows(() => doSomething(foo), foo, 'did not do something')

Was there a particular reason to only let assertions take a single message argument?

@sindresorhus
Copy link
Member

Was there a particular reason to only let assertions take a single message argument?

Simplicity. Having variadic parameters makes the assertions hard to read. We could consider supporting an array as an argument or having a t.format() method you pass to it.

@novemberborn
Copy link
Member

We have #1125 which enforces message to be a string. I just realized we should try and land that for 1.0.

We could consider supporting an array as an argument or having a t.format() method you pass to it.

I like the idea of having a function that does the formatting and returns an object that is recognized by the assertions. Perhaps not on t though. How about test.message(any, 'possible', argument, 'like t.log')? And then t.is(true, false, test.message('hello')? t.log() could also accept this value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants