-
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
assert API design #142
Comments
Could you please attach some code to both of these? I just tested the first one and it works as expected, even when I don't set import test from '.';
test(t => {
t.throws(function () {
throw new Error('damn it');
});
t.throws(Promise.reject(new Error('damn it')));
t.end();
}); |
@vdemedes That is true, it works but:
test(t => {
t.throws(()=>{}, 'some message');
t.end();
}); Before #125:
After:
About t.is('actual', 'expected');
t.regexTest(/expected/, 'actual'); |
Then the notation should be something like this
|
@SamVerschueren That is possible and I would recommend that, even though switching from assert.throws is no longer so simple. |
This is mentioned by @sindresorhus a couple of times, as well in #125.
That assertion module is not a binding contract. That's also the reason why AVA isn't using the same names as the |
@SamVerschueren I knew that and I like #125, the problem is, in contrast to most assertions in AVA, the name ( Maybe we should introduce our own throws assertions with a different name, in particular, because nodes try {
assert.throws(()=>{ throw new Error('abc')}, TypeError);
} catch (err) {
console.log(err instanceof assert.AssertionError);
//=> false
console.log(err.message);
//=> 'abc'
// I would expect something like:
console.log(err.message);
//=>'Missing expected TypeError. Got unwanted exception Error('abc').'
} |
Not sure about a name change, IMO people should read the docs, and I understand that some of them might think it has the same syntax, but then again, I guess @sindresorhus would be happy to give his thoughts on this. |
I think of more powerful assertions, maybe with different parameters. As this would also support Promises, EDIT: or |
If we go for a name change, I would not keep It's certainly not up to me to make this decisions. |
Oh no, let's not change the name of All we have to do, is to fix & stabilize issues pointed out in the first comment. |
I would prefer not to change the name of As for |
Thoughts on deprecating |
@sindresorhus I'd leave it, but rename to just t.regex(/ok/, 'oh ok');
t.true(/ok/.test('oh ok')); |
I'm with @vdemedes on this one. Would leave it as well. |
@vdemedes But the current one has the wrong argument order. I suggest we deprecate t.regex('oh ok', /ok/); |
@sindresorhus oh, in that case, definitely, |
In my opinion, reducing APIs that are easy to make mistakes is the most valuable point of power-assert. So I'm 👍 on (But for this purpose I must improve output depth of SuccinctRenderer! ) |
As we'll probably remove or replace it. #142 (comment)
Is Oh and do excuse the potential necro. Just scouring through the |
It is still on the table. Go for it! |
Commuting tomorrow morning is gon' be fun, cheers! : ) |
I've just found out that the
error
argument of.throws
is not optionaland that
.regexTest
is not consistent with the rest of the assertions:because of its parameter order (all other assertions follow the basic scheme
(actual, expected, message)
).I'm not sure if these were intended…
The text was updated successfully, but these errors were encountered: