-
Notifications
You must be signed in to change notification settings - Fork 33
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
Component options check omits target
#312
Comments
Ah, but then the
so I'm wondering....
|
@yanick I think the sneaky removal of // 1. props as options
render(Comp, { someProp: 'foo' })
// 2. explicit props
render(Comp, { props: { someProp: 'foo' } }) If you want to name a prop the same as a component option, you need to use the second form. However, because If you write a component that has a prop named <script>
export let someProp
export let target
</script>
<!-- ... --> Then you may write the following call to // I think this will work, and `render` will not yell at me directly,
// but unbeknownst to me, `target` is pulled off and
// used in a different manner than I expect
render(Comp, { target: ..., someProp: ... }) After sitting with this for a bit, I think we only need a small fix: |
Aaaah, I see. And yup, I agree, that fix should do the trick. |
🎉 This issue has been resolved in version 4.2.2 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Overview
The
render
function ofsvelte-testing-library
has two "modes":render(Comp, { name: 'hello' })
render(Comp, { intro: true, props: { name: 'hello' } })
To do this, it checks the passed in options object against a list of known Svelte options, and if it detects one, it goes into "options mode". Otherwise, it uses "props mode."
The check list is missing
target
, which means tests for a component that has a prop namedtarget
will unexpectedly fail in "props mode".Expected behavior
target
cannot be intermixed with props, just like any other Svelte option:Actual behavior
The
target
option can be intermixed with props, where "target" will be pulled out and used as the DOM target and never passed to the component.Proposed change
Any change here should probably be considered a breaking change to the
render
API.The smallest fix I can think of here is to simply add a check for
target
.A slightly larger change would be to switch away from a checklist-based approach to a simple check for the
props
key. Ifprops
exists, treat the object as "options mode," otherwise treat is as "props" mode. The downside of this approach is that you'd be forced to specify an empty props object to trigger options mode, which feels annoying enough that it might disqualify the idea.An even larger change could be to make the second render argument props exclusively, and move all options (both Svelte and render) to the third argument
The text was updated successfully, but these errors were encountered: