Skip to content
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

feat: render component name in stub #606

Merged
merged 2 commits into from
May 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions packages/shared/stub-components.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ function createStubFromString (templateString: string, originalComponent: Compon
function createBlankStub (originalComponent: Component) {
return {
...getCoreProperties(originalComponent),
render: h => h('')
render (h) {
return h(`${originalComponent.name}-stub`)
}
}
}

Expand All @@ -78,7 +80,7 @@ export function createComponentStubs (originalComponents: Object = {}, stubs: Ob
if (typeof stub !== 'string') {
throwError('each item in an options.stubs array must be a string')
}
components[stub] = createBlankStub({})
components[stub] = createBlankStub({ name: stub })
})
} else {
Object.keys(stubs).forEach(stub => {
Expand All @@ -89,7 +91,7 @@ export function createComponentStubs (originalComponents: Object = {}, stubs: Ob
throwError('options.stub values must be passed a string or component')
}
if (stubs[stub] === true) {
components[stub] = createBlankStub({})
components[stub] = createBlankStub({ name: stub })
return
}

Expand Down Expand Up @@ -124,7 +126,7 @@ export function createComponentStubs (originalComponents: Object = {}, stubs: Ob
}
// ignoreElements does not exist in Vue 2.0.x
if (Vue.config.ignoredElements) {
Vue.config.ignoredElements.push(stub)
Vue.config.ignoredElements.push(`${stub}-stub`)
}
})
}
Expand All @@ -142,7 +144,7 @@ function stubComponents (components: Object, stubbedComponents: Object) {

// ignoreElements does not exist in Vue 2.0.x
if (Vue.config.ignoredElements) {
Vue.config.ignoredElements.push(component)
Vue.config.ignoredElements.push(`${components[component].name}-stub`)
}
})
}
Expand Down
4 changes: 2 additions & 2 deletions packages/test-utils/src/wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ export default class Wrapper implements BaseWrapper {
*/
setData (data: Object) {
if (this.isFunctionalComponent) {
throwError('wrapper.setData() canot be called on a functional component')
throwError('wrapper.setData() cannot be called on a functional component')
}

if (!this.vm) {
Expand Down Expand Up @@ -505,7 +505,7 @@ export default class Wrapper implements BaseWrapper {
*/
setProps (data: Object) {
if (this.isFunctionalComponent) {
throwError('wrapper.setProps() canot be called on a functional component')
throwError('wrapper.setProps() cannot be called on a functional component')
}
if (!this.isVueComponent || !this.vm) {
throwError('wrapper.setProps() can only be called on a Vue instance')
Expand Down
6 changes: 3 additions & 3 deletions test/specs/mounting-options/stubs.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ describeWithMountingMethods('options.stub', (mountingMethod) => {
const HTML = mountingMethod.name === 'renderToString'
? wrapper
: wrapper.html()
expect(HTML).to.contain('<!---->')
expect(HTML).to.contain('<registered-component-stub>')
})

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

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

it('handles components without a render function', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/specs/wrapper/setData.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ describeWithShallowAndMount('setData', (mountingMethod) => {
render: (h, context) => h('div', context.prop1),
functional: true
}
const message = '[vue-test-utils]: wrapper.setData() canot be called on a functional component'
const message = '[vue-test-utils]: wrapper.setData() cannot be called on a functional component'
const fn = () => mountingMethod(AFunctionalComponent).setData({ data1: 'data' })
expect(fn).to.throw().with.property('message', message)
// find on functional components isn't supported in Vue < 2.3
Expand Down
2 changes: 1 addition & 1 deletion test/specs/wrapper/setProps.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describeWithShallowAndMount('setProps', (mountingMethod) => {
render: (h, context) => h('div', context.prop1),
functional: true
}
const message = '[vue-test-utils]: wrapper.setProps() canot be called on a functional component'
const message = '[vue-test-utils]: wrapper.setProps() cannot be called on a functional component'
const fn = () => mountingMethod(AFunctionalComponent).setProps({ prop1: 'prop' })
expect(fn).to.throw().with.property('message', message)
// find on functional components isn't supported in Vue < 2.3
Expand Down