Bri*_*yko 5 unit-testing vue.js vue-test-utils vuejs3 vue-composition-api
我目前正在处理一个遗留的 Vue 项目。我们正在使用带有选项 API 的 Vue 2.xw/Typescript。
我想提出切换到 Vue 组件 API 的案例,到目前为止,我认为这是一个非常引人注目的案例 - 除了一个缺点。
那就是——我们现有的测试失败了。具体来说,这是因为两个原因:
例子:
// 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
});
Run Code Online (Sandbox Code Playgroud)
// 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();
});
Run Code Online (Sandbox Code Playgroud)
坦率地说,如果我能弄清楚如何解决这些问题,我可以提出一个完整的建议,迁移到 VueComponentAPI 并让一些开发人员非常高兴。如果我不能,那么我就不能推荐它,并且必须坚持使用 Vue Options API。
有任何想法吗?
归档时间: |
|
查看次数: |
1048 次 |
最近记录: |