-
Notifications
You must be signed in to change notification settings - Fork 29
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
addAssertion-weirdness #339
Comments
(Also marginally related to #255 - set-like things are really nice when doing integration-style testing) |
Yes that can definitely be improved.
|
It might be helpful to show the signature of what you entered when there is a type miss match.
|
…h "assertion not found". As suggested by @sunesimonsen on #339
Implemented @sunesimonsen's suggestion here: #364 @msiebuhr, do you think the problem you originally reported gets solved by this? |
Not really. The issue is that
Adhering to the element of least surprise, I should be able to:
|
We could chose to write out a warning if you use that syntax and remove it later. |
Oh, now I understand :) Yeah, omitting the subject type and value types is allowed for compatibility with Unexpected 9 and below. It's essentially (but not 100%) an alias for
That does work, doesn't it? It should declare an assertion that doesn't take any parameters (except the subject): expect.addAssertion('<any> to foo', function (expect, subject) {
expect(String(subject), 'to equal', 'foo')
});
expect('foo', 'to foo');
expect({toString: () => 'foo'}, 'to foo'); What doesn't work is omitting the types of the parameters when omitting the type of the subject, like this: expect.addAssertion('to foo <number>', ...);
// Doesn't work, you have to use the full Unexpected 10 syntax and include the subject type as well.
// Throws: SyntaxError: Missing subject type in to foo <number>
// Doesn't do what you'd expect, since specifying a subject type but no parameter types
// means that the assertion doesn't take any parameters:
expect.addAssertion('<any> to do something with parameters', (expect, subject, param1) => {
expect(param1, ...);
});
expect('foo', 'to do something with parameters', 123);
// Throws:
// expected 'foo' to do something with parameters 123
// The assertion does not have a matching signature for:
// <string> to do something with parameters <number>
// did you mean:
// <any> to do something with parameters In the latter case the type system complains because I'm guessing that's what you've run into because expect('<any> to contain <any+>', (expect, subject, param1, param2...) => {
// ...
}); |
Hmm, maybe we should warn about this case when expect.addAssertion('<any> to foo', (expect, subject, value) => {
// ...
});
// Error: The provided function takes more params than are defined by the type signature |
@papandreou that sounds like a nice idea, as long as we are only warning about more than the defined number of params. |
Yeah, warning for less would be too daring, especially considering how > ((...rest) => {}).length
0
> ((a, ...rest) => {}).length
1 |
Implemented the idea here: #372 |
All calls to
addAssertion()
is on the form of<type> [not] to ...
:And running it gives:
Except when using the
any
-type; then it'saddAssertion('[not] to ...')
, which took me a while to figure out, given the error seem to tell me I'm doing things right...The text was updated successfully, but these errors were encountered: