-
Notifications
You must be signed in to change notification settings - Fork 78
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
Throwing an error on missing selector in test harness trigger #320
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! Probably should be considered a breaking change.
} | ||
|
||
if (!firstItem) { | ||
throw new Error(`Cannot find node with selector ${selector}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this error message. It might be good to make this and the assertion template errors consistent.
throw Error('Node not found'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't disagree, but updating the message there is a bit more complicated. I've made the change though, we'll see how it goes 😄
src/testing/assertionTemplate.ts
Outdated
if (!node) { | ||
throw Error('Node not found'); | ||
throw Error(`Cannot find node with selector ${selector}`); | ||
} | ||
if (!isWNode(node) && !isVNode(node)) { | ||
throw Error('Cannot set or get on unknown node'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm I don’t think we should change this. The findOne is meant to be equivalent to querySelector and not throw. It also doesn’t make sense to throw a setting unknown node here given the function name?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hehe, yeah, I wasn't sure about these changes. The other option is i can pass the selector in guard
so it can use it in the error message, but thats going to end up looking silly and be a bit of a pain every time you call it. Maybe i should just remove that last commit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ha yeah I agree, maybe for now we just stick with the trigger change and we can raise a separate issue for making error messages more consistent (it might be that we use the same function in the harness and assertion template)
This reverts commit f1fb897.
Type: bug / feature
The following has been addressed in the PR:
prettier
as per the readme code style guidelinesDescription:
Instead of silently failing, throwing an error when a
h.trigger
encounters a selector that doesn't return any nodes.Resolves #318