Vue test-utils 的问题 - TypeError: (0 , _testUtils.enableAutoDestroy) is not a function

时间:2021-07-29 11:34:02

标签: vue.js testing jestjs vue-test-utils

我正在用 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.

问题出在哪里?

0 个答案:

没有答案