I'm currently working on a legacy Vue project. We're using Vue 2.x w/ Typescript, with the Options API.
I'd like to make the case to switch to the Vue Component API, and so far I think it's a really compelling case - except for one drawback.
And that is - our existing tests fail. Specifically, this is because of two reasons:
Example:
// FIXME: This test fails because Vue Test Utils .setData does not work
// with the new composition API.
it("renders by default", async () => {
await wrapper.setData({
crosshairCoordinates: [{ x: 0, y: 0 }],
});
expect(wrapper.findAllComponents(ChartTooltip).length)
.toBe(1); // -> expected 1, recieved: 0
});
// FIXME: This test fails because Vue Test Utils findComponent doesn't work
// with the way Refs are handled with the Vue Composition API.
it("should be default and not emit event on mouse move", async () => {
const chartWrapper = wrapper.findComponent({ ref: "wrapper" });
chartWrapper.trigger("mousemove"); // -> TypeError Cannot read property 'ref' of undefined
expect(wrapper.emitted("mousemove")).toBeFalsy();
});
Quite frankly, if I can figure out how to resolve these issues, I can make a full recommendation to move to the VueComponentAPI and make some developers very happy. If I can't, then I can't recommend it and will have to stick with the Vue Options API.
Any ideas?
wrapper.setData({foo: 'bar'})
you can use wrapper.vm.foo = 'bar'
wrapper.findComponent()
did not change in any way. keep in mind that wrapper.findComponent({ ref: "foo" })
might return empty wrapper if the ref is not a component but an html elementIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With