Skip to content

Commit bfd070d

Browse files
authored
fix: Remove methods key from mount (#1145)
1 parent 4108a43 commit bfd070d

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/mount.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ const MOUNT_OPTIONS: Array<keyof MountingOptions<any>> = [
5757
function getInstanceOptions(
5858
options: MountingOptions<any> & Record<string, any>
5959
): Record<string, any> {
60+
if (options.methods) {
61+
console.warn(
62+
"Passing a `methods` option to mount was deprecated on Vue Test Utils v1, and it won't have any effect on v2. For additional info: https://vue-test-utils.vuejs.org/upgrading-to-v1/#setmethods-and-mountingoptions-methods"
63+
)
64+
delete options.methods
65+
}
66+
6067
const resultOptions = { ...options }
6168
for (const key of Object.keys(options)) {
6269
if (MOUNT_OPTIONS.includes(key as keyof MountingOptions<any>)) {
@@ -65,6 +72,7 @@ function getInstanceOptions(
6572
}
6673
return resultOptions
6774
}
75+
6876
// Class component - no props
6977
export function mount<V>(
7078
originalComponent: {

tests/mountingOptions/options.spec.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,24 @@ describe('mounting options: other', () => {
1010
})
1111
expect(wrapper.vm.$options.someUnknownOption).toBe(optionContent)
1212
})
13+
14+
it('warns on deprecated `method` option and methods are preserved', () => {
15+
const spy = jest.spyOn(console, 'warn').mockImplementationOnce(() => {})
16+
17+
const TestComponent = defineComponent({
18+
template: '<div>{{ sayHi() }}</div>',
19+
methods: {
20+
sayHi() {
21+
return 'hi'
22+
}
23+
}
24+
})
25+
26+
const wrapper = mount(TestComponent, { methods: {} })
27+
28+
expect(spy).toHaveBeenCalledTimes(1)
29+
expect(wrapper.html()).toBe('<div>hi</div>')
30+
31+
spy.mockRestore()
32+
})
1333
})

0 commit comments

Comments
 (0)