-
Notifications
You must be signed in to change notification settings - Fork 668
Hyphens are stripped from kebab-case attributes when camelCase props present #1190
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
Comments
I have the same issue after upgrading Webpack from 1 to 4. // Before
<loader-bar-stub
is-loading="true"
/>
// After
<loader-bar-stub
isloading="true"
/> I don't know which lib converted it. Maybe I'm using babel 6 and [email protected] |
Hi @hectorguo! Just to cross off some stuff from the list, is it possible for you to update to latest version of vue-test-utils (v1.0.3) and check if the issue is still there? |
Hi @afontcu, thanks for the quick response. I've found the root cause and got a working solution. The reason is because of this line code: Previously, I'm using Before upgrading, the After changing to Root CauseHowever, this line code is passing Vue props to HTML attributes. In Vue render, all HTML attributes will be converted to lowercase since they are case insensitive. So when creating stub components, if the props are camelCase, it will be converted to lowercase instead of kebab-case. It's why the snapshot is different.
Here is a sandbox link to proof that Vue render is lowercasing SolutionThere are 2 solutions for it.
// To make sure there is always a default wrapping the component
// It's working great when upgrading webpack from v1 to v4
const componentOptions = resolveOptions(originalComponent.default ? originalComponent : { default: originalComponent }, _Vue)
render: function render(h, context) {
// it will make sure camelCase props will be converted to kebab-case
// e.g. `{ isLoading: true } ` to `{ 'is-loading': true }`
const hyphenatedProps = Object.keys(this.$props).reduce((acc, key) => {
const hyphenatedKey = hyphenate(key);
acc[hyphenatedKey] = this.$props[key];
return acc;
}, {})
return h(
tagName,
{
attrs: componentOptions.functional
? Object.assign({}, context.props,
context.data.attrs,
{class: createClassString(
context.data.staticClass,
context.data.class
)})
: hyphenatedProps
},
context ? context.children : this.$options._renderChildren
)
}}) I really hope that it can be fixed in current version instead of hacking by myself. |
Struggling with this issue since while upgrading to the latest @vue/test-utils version (1.2.1). Stubs' attributes are created as merged lowercase strings, therefore, attributes such as "data-test" become "datatest" and then most selectors are breaking. Is there any temporary fix that can be done? |
Version
1.0.0-beta.29
Reproduction link
https://github.com/ctbradley/vue-test-utils-demo
Steps to reproduce
npm i
npm run test
or run using wallaby...
the most relevant files are:
src/components/HelloWorld.vue
src/components/HelloWorld.test.ts
src/components/VForm.vue
comment out props in
VForm.vue
to demonstrate behaviorWhat is expected?
VFormImport attributes are expected as kebab-case.
What is actually happening?
VFormImport attributes are being stripped of their hyphens.
Note that this only affects components that are being imported as demonstrated in
src/components/HelloWorld.test.ts
.The text was updated successfully, but these errors were encountered: