Checks that mount and shallowMount options are valid for the current version of VTU. (vue-test-utils/no-deprecated-mount-options)
The --fix
option on the command line can automatically fix some of the problems reported by this rule.
This rule reports when mount options that are deprecated or unsupported in the current version of VTU are used.
This rule has an object option:
ignoreMountOptions
can be set to an array of property names that are ignored when checking for deprecated mount options.- This option is primarily useful when using a compatibility layer for Vue 3 or VTU 2 such as
@vue/compat
orvue-test-utils-compat
.
- This option is primarily useful when using a compatibility layer for Vue 3 or VTU 2 such as
Examples of incorrect code for this rule:
/* eslint vue-test-utils/no-deprecated-mount-options: "error" */
import { mount } from '@vue/test-utils';
// VTU 1
mount(MyComponent, {
attachToDocument: true,
});
mount(MyComponent, {
computed: { /* ... */ }
methods: { /* ... */ },
});
// VTU 2
mount(MyComponent, {
propsData: { /* ... */ }
})
mount(MyComponent, {
stubs: [/* ... */]
})
Examples of correct code for this rule:
/* eslint vue-test-utils/no-deprecated-mount-options: "error" */
import { mount } from '@vue/test-utils';
// VTU 1
mount(MyComponent, {
attachTo: document.body,
});
mount(MyComponent, {
mixins: [
/* ... */
],
});
// VTU 2
mount(MyComponent, {
props: {
/* ... */
},
});
mount(MyComponent, {
global: {
stubs: [
/* ... */
],
},
});
Examples of correct code with the { "ignoreMountOptions": ["store", "scopedSlots"] }
option:
/* eslint vue-test-utils/no-deprecated-mount-options: ["error", { "ignoreMountOptions": ["store", "scopedSlots"] }] */
import { mount } from '@vue/test-utils';
// VTU 2
mount(MyComponent, {
store: createStore(/* ... */),
});
mount(MyComponent, {
scopedSlots: {
/* ... */
},
});
- This rule cannot detect mount options if they are passed via a variable (eg,
let context = { methods: {} }; mount(Foo, context)
will never error). - This rule cannot detect mount options passed via object spread or if the mount option keys are not identifiers (eg,
mount(Foo, { ...context }))
andmount(Foo, { ['methods']: {} })
will never error).
- You don't plan to update to Vue 3/VTU 2