Skip to content

Commit dbf63bb

Browse files
authored
feat: render component name in stub (#606)
1 parent 934745b commit dbf63bb

File tree

5 files changed

+14
-12
lines changed

5 files changed

+14
-12
lines changed

Diff for: packages/shared/stub-components.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ function createStubFromString (templateString: string, originalComponent: Compon
6060
function createBlankStub (originalComponent: Component) {
6161
return {
6262
...getCoreProperties(originalComponent),
63-
render: h => h('')
63+
render (h) {
64+
return h(`${originalComponent.name}-stub`)
65+
}
6466
}
6567
}
6668

@@ -78,7 +80,7 @@ export function createComponentStubs (originalComponents: Object = {}, stubs: Ob
7880
if (typeof stub !== 'string') {
7981
throwError('each item in an options.stubs array must be a string')
8082
}
81-
components[stub] = createBlankStub({})
83+
components[stub] = createBlankStub({ name: stub })
8284
})
8385
} else {
8486
Object.keys(stubs).forEach(stub => {
@@ -89,7 +91,7 @@ export function createComponentStubs (originalComponents: Object = {}, stubs: Ob
8991
throwError('options.stub values must be passed a string or component')
9092
}
9193
if (stubs[stub] === true) {
92-
components[stub] = createBlankStub({})
94+
components[stub] = createBlankStub({ name: stub })
9395
return
9496
}
9597

@@ -124,7 +126,7 @@ export function createComponentStubs (originalComponents: Object = {}, stubs: Ob
124126
}
125127
// ignoreElements does not exist in Vue 2.0.x
126128
if (Vue.config.ignoredElements) {
127-
Vue.config.ignoredElements.push(stub)
129+
Vue.config.ignoredElements.push(`${stub}-stub`)
128130
}
129131
})
130132
}
@@ -142,7 +144,7 @@ function stubComponents (components: Object, stubbedComponents: Object) {
142144

143145
// ignoreElements does not exist in Vue 2.0.x
144146
if (Vue.config.ignoredElements) {
145-
Vue.config.ignoredElements.push(component)
147+
Vue.config.ignoredElements.push(`${components[component].name}-stub`)
146148
}
147149
})
148150
}

Diff for: packages/test-utils/src/wrapper.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ export default class Wrapper implements BaseWrapper {
413413
*/
414414
setData (data: Object) {
415415
if (this.isFunctionalComponent) {
416-
throwError('wrapper.setData() canot be called on a functional component')
416+
throwError('wrapper.setData() cannot be called on a functional component')
417417
}
418418

419419
if (!this.vm) {
@@ -506,7 +506,7 @@ export default class Wrapper implements BaseWrapper {
506506
*/
507507
setProps (data: Object) {
508508
if (this.isFunctionalComponent) {
509-
throwError('wrapper.setProps() canot be called on a functional component')
509+
throwError('wrapper.setProps() cannot be called on a functional component')
510510
}
511511
if (!this.isVueComponent || !this.vm) {
512512
throwError('wrapper.setProps() can only be called on a Vue instance')

Diff for: test/specs/mounting-options/stubs.spec.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ describeWithMountingMethods('options.stub', (mountingMethod) => {
123123
const HTML = mountingMethod.name === 'renderToString'
124124
? wrapper
125125
: wrapper.html()
126-
expect(HTML).to.contain('<!---->')
126+
expect(HTML).to.contain('<registered-component-stub>')
127127
})
128128

129129
it('stubs components with dummy when passed a boolean', () => {
@@ -138,7 +138,7 @@ describeWithMountingMethods('options.stub', (mountingMethod) => {
138138
const HTML = mountingMethod.name === 'renderToString'
139139
? wrapper
140140
: wrapper.html()
141-
expect(HTML).to.contain('<!---->')
141+
expect(HTML).to.contain('<registered-component-stub>')
142142
})
143143

144144
it('stubs components with dummy when passed as an array', () => {
@@ -287,7 +287,7 @@ describeWithMountingMethods('options.stub', (mountingMethod) => {
287287
const HTML = mountingMethod.name === 'renderToString'
288288
? wrapper
289289
: wrapper.html()
290-
expect(HTML).to.contain('<!----></div>')
290+
expect(HTML).to.contain('<time-component-stub>')
291291
})
292292

293293
it('handles components without a render function', () => {

Diff for: test/specs/wrapper/setData.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ describeWithShallowAndMount('setData', (mountingMethod) => {
6666
render: (h, context) => h('div', context.prop1),
6767
functional: true
6868
}
69-
const message = '[vue-test-utils]: wrapper.setData() canot be called on a functional component'
69+
const message = '[vue-test-utils]: wrapper.setData() cannot be called on a functional component'
7070
const fn = () => mountingMethod(AFunctionalComponent).setData({ data1: 'data' })
7171
expect(fn).to.throw().with.property('message', message)
7272
// find on functional components isn't supported in Vue < 2.3

Diff for: test/specs/wrapper/setProps.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ describeWithShallowAndMount('setProps', (mountingMethod) => {
4141
render: (h, context) => h('div', context.prop1),
4242
functional: true
4343
}
44-
const message = '[vue-test-utils]: wrapper.setProps() canot be called on a functional component'
44+
const message = '[vue-test-utils]: wrapper.setProps() cannot be called on a functional component'
4545
const fn = () => mountingMethod(AFunctionalComponent).setProps({ prop1: 'prop' })
4646
expect(fn).to.throw().with.property('message', message)
4747
// find on functional components isn't supported in Vue < 2.3

0 commit comments

Comments
 (0)