I am learning how to unit test in vue. I would like to know how to test a method. I am using jest and vue test utils. In the vue documentation I can't find anything similar to test a method.
So far, what I have is the following
introducir el código aquíimport { shallowMount } from '@vue/test-utils'
import Usuario from '@/components/Usuario.vue'
describe('componente Usuario.vue', () => {
it('calls testMethod on mount', () => {
const wrapper = shallowMount(Usuario, {
methods: {
activarUsuario
}
})
wrapper.vm.activarUsuario = jest.fn()
expect(activarUsuario).toBeCalled()
});
})
If you need to test that the button has been called and mock the function you can do it like this:
You can also test the method directly like this