Skip to content

Commit 9e20dc9

Browse files
authored
test: add extra tests for sub class components (#901)
1 parent 44c4520 commit 9e20dc9

File tree

2 files changed

+39
-16
lines changed

2 files changed

+39
-16
lines changed

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

+17-16
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { createLocalVue, config } from '~vue/test-utils'
22
import Vue from 'vue'
33
import Component from '~resources/components/component.vue'
44
import ComponentWithVuex from '~resources/components/component-with-vuex.vue'
5-
import { describeWithMountingMethods, vueVersion } from '~resources/utils'
5+
import { describeWithMountingMethods } from '~resources/utils'
66
import { itDoNotRunIf } from 'conditional-specs'
77

88
describeWithMountingMethods('options.mocks', mountingMethod => {
@@ -42,26 +42,27 @@ describeWithMountingMethods('options.mocks', mountingMethod => {
4242
expect(HTML).contains('http://test.com')
4343
})
4444

45-
itDoNotRunIf(
46-
vueVersion < 2.3,
47-
'adds variables to extended components', () => {
48-
const TestComponent = Vue.extend({
49-
template: `
45+
it('adds variables to extended components', () => {
46+
const extendedComponent = Vue.extend({
47+
name: 'extended-component'
48+
})
49+
const TestComponent = extendedComponent.extend({
50+
template: `
5051
<div>
5152
{{$route.path}}
5253
</div>
5354
`
54-
})
55-
const $route = { path: 'http://test.com' }
56-
const wrapper = mountingMethod(TestComponent, {
57-
mocks: {
58-
$route
59-
}
60-
})
61-
const HTML =
62-
mountingMethod.name === 'renderToString' ? wrapper : wrapper.html()
63-
expect(HTML).contains('http://test.com')
6455
})
56+
const $route = { path: 'http://test.com' }
57+
const wrapper = mountingMethod(TestComponent, {
58+
mocks: {
59+
$route
60+
}
61+
})
62+
const HTML =
63+
mountingMethod.name === 'renderToString' ? wrapper : wrapper.html()
64+
expect(HTML).contains('http://test.com')
65+
})
6566

6667
// render returns a string so reactive does not apply
6768
itDoNotRunIf(

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

+22
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,28 @@ describeWithMountingMethods('options.stub', mountingMethod => {
8787
})
8888
})
8989

90+
it('overrides components in extended components', () => {
91+
const extendedComponent = Vue.extend({
92+
name: 'extended-component',
93+
components: {
94+
ToStubComponent: {
95+
template: '<span />'
96+
}
97+
}
98+
})
99+
const TestComponent = extendedComponent.extend({
100+
template: `<to-stub-component />`
101+
})
102+
const wrapper = mountingMethod(TestComponent, {
103+
stubs: {
104+
ToStubComponent: { template: '<date />' }
105+
}
106+
})
107+
const HTML =
108+
mountingMethod.name === 'renderToString' ? wrapper : wrapper.html()
109+
expect(HTML).contains('<date')
110+
})
111+
90112
itDoNotRunIf(
91113
mountingMethod.name === 'shallowMount' ||
92114
mountingMethod.name === 'renderToString',

0 commit comments

Comments
 (0)