I wrote a global plugin and used it in a component.
plugins/passwordValidation.js:
export default function ({ app }, inject) {
inject('passwordValidation', (password, passwordForConfirming) => {
const errors = []
...
return errors
})
}
...
<script>
...
export default {
...
watch: {
password(newPassword, oldPassword) {
this.passwordValidationWarnings = this.$passwordValidation(
newPassword,
this.passwordForConfirming
)
},
...
}
</script>
Then after writing a test with reference to the documentation, I noticed an following error occurred.
An error message:
FAIL test/components/organisms/RegisterForm.spec.js
● Test suite failed to run
TypeError: inject is not a function
1 | export default function ({ app }, inject) {
> 2 | inject('passwordValidation', (password, passwordForConfirming) => {
| ^
3 | const errors = []
test/components/organisms/RegisterForm.spec.js:
import { createLocalVue, shallowMount } from '@vue/test-utils'
import Vuex, { Store } from 'vuex'
import RegisterForm from '@/components/organisms/RegisterForm.vue'
import passwordValidation from '@/plugins/passwordValidation.js'
const localVue = createLocalVue()
localVue.use(Vuex)
localVue.use(passwordValidation)
describe('RegisterForm', () => {
describe('When the registration succeeds', () => {
beforeEach(() => {
...
wrapper = shallowMount(RegisterForm, {
localVue,
...
})
...
})
How can I fix this error to use the plugin in my test?
For reference, the versions of the applications used are as follows.
- nuxt: 2.15.8
- @vue/test-utils: 1.3.0
- jest: 27.5.1
Comments
Post a Comment