Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 80df0d2

Browse files
authoredJul 28, 2021
fix(compat): Do not wrap legacy options component with extra wrap (#777)
1 parent 67c3e60 commit 80df0d2

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed
 

‎src/mount.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
ComponentOptionsWithArrayProps,
1010
ComponentOptionsWithoutProps,
1111
ExtractPropTypes,
12-
WritableComputedOptions,
1312
AppConfig,
1413
VNodeProps,
1514
ComponentOptionsMixin,
@@ -38,7 +37,10 @@ import { createWrapper, VueWrapper } from './vueWrapper'
3837
import { attachEmitListener } from './emit'
3938
import { createDataMixin } from './dataMixin'
4039
import { createStub, stubComponents, addToDoNotStubComponents } from './stubs'
41-
import { isLegacyFunctionalComponent } from './utils/vueCompatSupport'
40+
import {
41+
isLegacyFunctionalComponent,
42+
unwrapLegacyVueExtendComponent
43+
} from './utils/vueCompatSupport'
4244

4345
// NOTE this should come from `vue`
4446
type PublicProps = VNodeProps & AllowedComponentProps & ComponentCustomProps
@@ -218,10 +220,11 @@ export function mount<
218220

219221
// implementation
220222
export function mount(
221-
originalComponent: any,
223+
inputComponent: any,
222224
options?: MountingOptions<any>
223225
): VueWrapper<any> {
224226
// normalise the incoming component
227+
let originalComponent = unwrapLegacyVueExtendComponent(inputComponent)
225228
let component: ConcreteComponent
226229

227230
if (

‎tests-compat/compat.spec.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,4 +130,17 @@ describe('@vue/compat build', () => {
130130

131131
expect(wrapper.html()).toBe('<div>stubbed</div>')
132132
})
133+
134+
it('wrapper.vm points to correct instance when component is wrapped with Vue.extend', () => {
135+
const Component = extend({
136+
data() {
137+
return { foo: 'bar' }
138+
},
139+
template: '<div></div>'
140+
})
141+
142+
const wrapper = mount(Component)
143+
144+
expect(wrapper.vm.foo).toBe('bar')
145+
})
133146
})

0 commit comments

Comments
 (0)
Please sign in to comment.