Consider the code snippet below:
import { mapState } from 'vuex';
import externalDependency from '...';
export default {
name: 'Foo',
computed: {
...mapState(['bar'])
},
watch: {
bar () {
externalDependency.doThing(this.bar);
}
}
}
During testing, I need to verify that externalDependency.doThing()
is invoked with the value of bar
(obtained from the vuex state) as follows:
it('should call externalDependency.doThing with bar', () => {
const wrapper = mount(Foo);
const spy = jest.spyOn(externalDependency, 'doThing');
wrapper.setComputed({bar: 'baz'});
expect(spy).toHaveBeenCalledWith('baz');
});
Although Vue test-utils currently supports the use of setComputed method for testing, there are warnings indicating that setComputed will be deprecated soon. I am seeking alternative methods to achieve the same level of testing without relying on setComputed: