-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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.fail() accept an object #2615
Comments
It's worth exploring, sure. I'm concerned that properly integrating this with the reporters will be harder than expected. You'd also want to customize the stack trace to not start at the How would you set up custom assertions to use this? |
Here's an example of how a custom assertion might be defined: const test = require('ava');
const { Assertions } = require('ava/lib/assert');
Object.assign(Assertions.prototype, {
bla(actual, expected) {
if (!blaTest(actual, expected)) {
this.fail('error message');
} else {
this.pass();
}
}
})
test('bla test', (t) => {
t.bla(actual, expected);
}); This works but doesn't let us customize the actual error output from AVA. What if we could just modify the fail assertion to pass through an instance of I haven't seen most of the codebase, but wouldn't reporting work without modifications as long as AssertionError uses the same API? |
@dolsem my hunch is that exposes AVA internals more than we'd like. I like an option object better. |
@novemberborn well, if you don't want to expose |
I want to avoid accidental APIs that we then cannot change. I think there are too many internal considerations for how |
It seems like the only problem with #1094 is providing detailed error output when a custom assertion fails. Everything else is straightforward. What if
t.fail()
could accept an object to use for creating an AssertionError? The fields could bemessage
,actual
,expected
, andformat
that will specifying which formatting function to use for setting thevalues
field on the error object. Could also add an optionalassertion
field for a custom assertion name.Would this be compatible with #2435?
If there's interest, I can submit a PR for this.
The text was updated successfully, but these errors were encountered: