Skip to content

Commit 33a6731

Browse files
authored
fix: overwrites registered components for stubs (#585)
1 parent db8f393 commit 33a6731

File tree

4 files changed

+46
-2
lines changed

4 files changed

+46
-2
lines changed

packages/create-instance/create-instance.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,21 @@ export default function createInstance (
5959

6060
const instanceOptions = { ...options }
6161
deleteoptions(instanceOptions)
62+
// $FlowIgnore
63+
const stubComponents = createComponentStubs(component.components, options.stubs)
64+
6265
if (options.stubs) {
6366
instanceOptions.components = {
6467
...instanceOptions.components,
6568
// $FlowIgnore
66-
...createComponentStubs(component.components, options.stubs)
69+
...stubComponents
6770
}
6871
}
6972

73+
Object.keys(stubComponents).forEach(c => {
74+
vue.component(c, stubComponents[c])
75+
})
76+
7077
const vm = new Constructor(instanceOptions)
7178

7279
addAttrs(vm, options.attrs)

test/resources/utils.js

+20
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,14 @@ export function itSkipIf (predicate, spec, cb) {
8080
}
8181
}
8282

83+
itSkipIf.only = (predicate, spec, cb) => {
84+
if (predicate) {
85+
it.skip(spec, cb)
86+
} else {
87+
it.only(spec, cb)
88+
}
89+
}
90+
8391
export function itDoNotRunIf (predicate, spec, cb) {
8492
if (predicate) {
8593
() => {}
@@ -88,8 +96,20 @@ export function itDoNotRunIf (predicate, spec, cb) {
8896
}
8997
}
9098

99+
itDoNotRunIf.only = (predicate, spec, cb) => {
100+
if (!predicate) {
101+
it.only(spec, cb)
102+
}
103+
}
104+
91105
export function describeIf (predicate, spec, cb) {
92106
if (predicate) {
93107
describe(spec, cb)
94108
}
95109
}
110+
111+
describeIf.only = (predicate, spec, cb) => {
112+
if (predicate) {
113+
describe(spec, cb)
114+
}
115+
}

test/specs/mounting-options/stubs.spec.js

+17
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,23 @@ describeWithMountingMethods('options.stub', (mountingMethod) => {
248248
expect(HTML).to.contain('<span>')
249249
})
250250

251+
itDoNotRunIf(
252+
mountingMethod.name === 'shallow' ||
253+
mountingMethod.name === 'renderToString',
254+
'stubs on child components', () => {
255+
const TestComponent = {
256+
template: '<transition><span /></transition>'
257+
}
258+
259+
const wrapper = mountingMethod({
260+
components: { 'test-component': TestComponent },
261+
template: '<test-component />'
262+
}, {
263+
stubs: ['transition']
264+
})
265+
expect(wrapper.find('span').exists()).to.equal(false)
266+
})
267+
251268
it('converts config to array if stubs is an array', () => {
252269
const localVue = createLocalVue()
253270
config.stubs['time-component'] = '<p />'

test/specs/wrapper/setProps.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ describeWithShallowAndMount('setProps', (mountingMethod) => {
105105
expect(wrapper.text()).to.equal('There is no message yet')
106106
})
107107

108-
it.only('runs watchers correctly', () => {
108+
it('runs watchers correctly', () => {
109109
const TestComponent = {
110110
template: `<div id="app">
111111
{{ stringified }}

0 commit comments

Comments
 (0)