【问题标题】:Jest error: "preset @vue/cli-plugin-unit-jest/presets/typescript-and-babel not found"笑话错误:“未找到预设 @vue/cli-plugin-unit-jest/presets/typescript-and-babel”
【发布时间】:2021-06-23 07:31:40
【问题描述】:

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

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

我正在使用带有组合 API 插件和打字稿的 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)
  })
})

【问题讨论】:

  • 你的项目本地安装了this plugin吗?
  • 是的,我已将其安装为开发依赖项。

标签: typescript vue.js jestjs


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2021-03-18
    • 2021-03-15
    • 2020-04-09
    • 1970-01-01
    • 2019-06-12
    • 2021-06-24
    • 2019-07-07
    • 2021-03-03
    • 2020-02-10
    相关资源
    最近更新 更多