我正在用 Vue3 和 test-utils 做一些测试练习。我已经设置了以下组件:
<template>
<div>
<ul>
<li class="stars"></li>
<li class="stars"></li>
<li class="stars"></li>
<li class="stars"></li>
<li class="stars"></li>
</ul>
</div>
</template>
以及以下测试:
import { enableAutoDestroy, mount } from '@vue/test-utils';
import Rating from "@/components/common/Rating";
enableAutoDestroy(afterEach)
describe("Rating", () => {
it("renders the starts", () => {
const wrapper = mount(Rating);
const stars = wrapper.findAll(".stars");
expect(stars.length).toBe(5)
})
})
然后,在控制台上显示一个错误:
● Test suite failed to run
TypeError: (0 , _testUtils.enableAutoDestroy) is not a function
3 |
4 |
> 5 | enableAutoDestroy(afterEach)
| ^
6 |
7 | describe("Rating", () => {
8 | it("renders the starts", () => {
at Object.<anonymous> (tests/unit/Rating.spec.js:5:1)
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 2.696s
Ran all test suites.
error Command failed with exit code 1.
问题出在哪里?