首页 > 解决方案 > 使用 Jest 进行 Strapi 单元测试,失败

问题描述

我有一个 Strapi api 并试图运行一个单元测试

这是我得到的控制台中的错误

yarn test
yarn run v1.22.5
$ jest --forceExit --detectOpenHandles
  ●  process.exit called with "1"

       8 |   if (!instance) {
       9 |     /** the follwing code in copied from `./node_modules/strapi/lib/Strapi.js` */
    > 10 |     await Strapi().load();
         |     ^
      11 |     instance = strapi; // strapi is global now
      12 |     await instance.app
      13 |       .use(instance.router.routes()) // populate KOA routes

      at Strapi.stop (node_modules/strapi/lib/Strapi.js:263:13)
      at node_modules/strapi/lib/Strapi.js:391:16
          at async Promise.all (index 5)
      at Strapi.runBootstrapFunctions (node_modules/strapi/lib/Strapi.js:394:5)
      at Strapi.load (node_modules/strapi/lib/Strapi.js:326:5)
      at setupStrapi (tests/helpers/strapi.js:10:5)
      at Object.<anonymous> (tests/app.test.js:8:3)

 RUNS  tests/app.test.js
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

我完全按照这些说明进行操作。

我该如何解决这个问题?

谢谢

标签: node.jsjestjsstrapi

解决方案


通过将env文件夹名称更改为环境来解决该问题


推荐阅读