Translations: Français
Enforces passing the right number of arguments to assertion methods like t.is()
. This rule can optionally also enforce or forbid the use of assertion messages.
Assertion messages are optional arguments that can be given to any assertion call to improve the error message, should the assertion fail.
import test from 'ava';
test(t => {
t.is(value); // Not enough arguments
t.is(value, expected, message, extra); // Too many arguments
});
/* eslint ava/assertion-arguments: ["error", {"message": "always"}] */
test(t => {
t.true(array.includes(value));
});
/* eslint ava/assertion-arguments: ["error", {"message": "never"}] */
test(t => {
t.true(array.includes(value), 'value is not in array');
});
import test from 'ava';
test(t => {
t.is(value, expected);
t.is(value, expected, message);
});
/* eslint ava/assertion-arguments: ["error", {"message": "always"}] */
test(t => {
t.true(array.includes(value), 'value is not in array');
});
/* eslint ava/assertion-arguments: ["error", {"message": "never"}] */
test(t => {
t.true(array.includes(value));
});
This rule supports the following options:
message
: A string which could be either "always"
or "never"
. If set to "always"
, all assertions will need to have an assertion message. If set to "never"
, no assertion may have an assertion message. If omitted, no reports about the assertion message will be made.
You can set the option in configuration like this:
"ava/assertion-arguments": ["error", {"message": "always"}]