Skip to content

Commit 19a1dfe

Browse files
committed
fix(stub): rename prefix prop to avoid warning on render
1 parent 2d431d8 commit 19a1dfe

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

src/vnodeTransformers/stubComponentsTransformer.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,28 @@ interface StubOptions {
3737
renderStubDefaultSlot?: boolean
3838
}
3939

40+
const mapStubPropValue = (value: unknown) => {
41+
if (typeof value === 'symbol') {
42+
return value?.toString()
43+
} else if (typeof value === 'function') {
44+
return '[Function]'
45+
}
46+
47+
return value
48+
}
4049
const normalizeStubProps = (props: ComponentPropsOptions) => {
4150
// props are always normalized to object syntax
4251
const $props = props as unknown as ComponentObjectPropsOptions
4352
return Object.keys($props).reduce((acc, key) => {
44-
if (typeof $props[key] === 'symbol') {
45-
return { ...acc, [key]: $props[key]?.toString() }
46-
}
47-
if (typeof $props[key] === 'function') {
48-
return { ...acc, [key]: '[Function]' }
53+
let propName = key
54+
55+
// Rename `prefix` prop because it's shared with Element prop and will output a warning on render
56+
// https://developer.mozilla.org/en-US/docs/Web/API/Element/prefix
57+
if (propName === 'prefix') {
58+
propName = '_prefix'
4959
}
50-
return { ...acc, [key]: $props[key] }
60+
61+
return { ...acc, [propName]: mapStubPropValue($props[key]) }
5162
}, {})
5263
}
5364

tests/shallowMount.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ describe('shallowMount', () => {
246246
{ shallow: true }
247247
)
248248
expect(wrapper.html()).toBe(
249-
'<test-comp-stub prefix="foo"></test-comp-stub>'
249+
'<test-comp-stub _prefix="foo"></test-comp-stub>'
250250
)
251251

252252
expect(wrapper.findComponent(TestComp).props('prefix')).toBe('foo')

0 commit comments

Comments
 (0)