小编mat*_*rmv的帖子

在使用 jest 的 vue 测试中找不到模块“@jest/globals”

我正在尝试从我的项目中的 vue 文档编写一个非常简单的测试。我可以在我的项目中使用 jest 运行测试,但是一旦我尝试使用 jest 模拟 axios 请求,就会出现以下错误:

 FAIL  tests/unit/test.spec.js
Run Code Online (Sandbox Code Playgroud)

? 测试套件无法运行

Cannot find module '@jest/globals' from 'test.spec.js'

  14 |   })

  at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:259:17)
  at _getJestObj (tests/unit/test.spec.js:16:7)
  at Object.<anonymous> (tests/unit/test.spec.js:3:1)
Run Code Online (Sandbox Code Playgroud)

这是我的 Foo 组件:

<template>
  <button @click="fetchResults">{{ value }}</button>
</template>

<script>
  import axios from 'axios'

  export default {
    data() {
      return {
        value: null
      }
    },

    methods: {
      async fetchResults() {
        const response = await axios.get('mock/service')
        this.value = response.data
      }
    }
  }
</script>
Run Code Online (Sandbox Code Playgroud)

和相关的测试:

import { shallowMount } from '@vue/test-utils' …
Run Code Online (Sandbox Code Playgroud)

javascript testing vue.js jestjs

4
推荐指数
1
解决办法
3341
查看次数

标签 统计

javascript ×1

jestjs ×1

testing ×1

vue.js ×1