开玩笑错误:“找不到预设@vue/cli-plugin-unit-jest/presets/typescript-and-babel”

Luk*_*Gur 2 typescript vue.js jestjs

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

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

我正在使用 vue 2 与合成 api 插件和打字稿。

笑话.config.js:

module.exports = {
  preset: '@vue/cli-plugin-unit-jest/presets/typescript-and-babel'
}
Run Code Online (Sandbox Code Playgroud)

示例.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)
  })
})
Run Code Online (Sandbox Code Playgroud)

Luk*_*Gur 5

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