网站搜索

vue.js - Jest 错误:"未找到 preset @vue/cli-plugin-unit-jest/presets/typescript-and-babel"


我有默认的 jest.config.js,但当我想运行单元测试时,我收到一个错误消息:

验证错误:未找到预设 @vue/cli-plugin-unit-jest/presets/typescript-and-babel。

我正在使用带有组合 API 插件和 TypeScript 的 Vue 2。

jest.config.js:

module.exports = {
  preset: '@vue/cli-plugin-unit-jest/presets/typescript-and-babel'
}

example.spec.ts:

import { shallowMount } from '@vue/test-utils'
import HelloWorld from '@/components/HelloWorld.vue'

describe('HelloWorld.vue', () => {
  it('renders props.msg when passed', () => {
    const msg = 'new message'
    const wrapper = shallowMount(HelloWorld, {
      props: { msg }
    })
    expect(wrapper.text()).toMatch(msg)
  })
})

答案#1

我通过将 jest 插件从 @vue/cli-plugin-unit-jest": "^3.12.1" 更新到 @vue/cli-plugin-unit-jest": "^4.5.0" 解决了这个问题