I'd like to stub/spy a method and ensure/test that it is called during the created lifecycle hook. I've discovered that I can use wrapper.setMethods to stub/mock the method, but the created hook has already run at this point; I've tried using wrapper.update(), but it doesn't appear to run the created hook again.
Am I missing something simple?
You can pass a methods object in the mounting options that will overwrite any method inside the component.
Say you had a method called methodToStub in your component. You would mount like this:
mount(Component, {
methods: {
methodToStub: () => {}
}
})
See the issue #166 and the pending PR #167 that would solve this issue.
Thanks, @eddyerburgh! Passing methods to mount/shallow was exactly what I needed.
Most helpful comment
You can pass a
methodsobject in the mounting options that will overwrite any method inside the component.Say you had a method called
methodToStubin your component. You would mount like this: