如果有多个套件,则不显示测试内容

问题描述 投票:0回答:1

我正在测试我的应用。当我运行“ npm test”时,我想在终端中查看所有测试。我所有的测试都有一个名为auth.test.js的文件。

所以当我运行npm test时,我的输出就是这个:

> jest --forceExit

 PASS  src/test/auth.test.js
  /LOGIN testing
    ✓ Should not login a unexistent username. (22ms)
    ✓ Should not login with incorrect credentials. (63ms)
    ✓ Should not login with empty fields. (2ms)
    ✓ Should login a moked user. (67ms)
  /SIGNUP testing
    ✓ Should not sign up a new user with invalid password. (3ms)
    ✓ Should not sign up a new user with invalid username. (2ms)
    ✓ Should sign up a new user. (72ms)
    ✓ Should not sign up a existing user. (4ms)
    ✓ Should not sign up with empty fields. (3ms)

Test Suites: 1 passed, 1 total
Tests:       9 passed, 9 total
Snapshots:   0 total
Time:        1.114s, estimated 2s
Ran all test suites.

很好。我可以看到所有测试的详细信息。

现在,我想添加一个带有测试的新文件,名为api.tests.js。

然后,当我运行'npm test'时,我看到此输出:

> jest --forceExit

 PASS  src/test/api.test.js
 PASS  src/test/auth.test.js

Test Suites: 2 passed, 2 total
Tests:       10 passed, 10 total
Snapshots:   0 total
Time:        1.589s, estimated 2s
Ran all test suites.

阅读了笑话文档(cli文章)后,我找不到如何查看详细信息,就像测试1个文件时看到的一样,但是测试多个文件时却看到了。

可以吗?怎么做?

express testing jestjs command-line-interface tdd
1个回答
0
投票

您需要在testMatch文件中修改jest.config.js的配置。

Jest用于检测测试文件的全局模式。默认情况下,它将在tests文件夹中查找.js,.jsx,.ts和.tsx文件,以及带有.test或.spec后缀的任何文件(例如Component.test.js或Component。 spec.js)。它还会找到名为test.js或spec.js的文件。

您的新测试文件名为api.tests.js,因此您需要添加全局模式

['**/?(*.)+(specs|tests).[jt]s?(x)'进入testMatch配置。

例如,jest.config.js

module.exports = {
  preset: 'ts-jest',
  testEnvironment: 'enzyme',
  setupFilesAfterEnv: ['jest-enzyme'],
  testEnvironmentOptions: {
    enzymeAdapter: 'react16'
  },
  coverageReporters: ['json', 'text', 'lcov', 'clover'],
  testMatch: ['**/__tests__/**/*.[jt]s?(x)', '**/?(*.)+(spec|test).[jt]s?(x)', '**/?(*.)+(specs|tests).[jt]s?(x)']
};

单元测试结果:

☁  jest-codelab [master] ⚡  npm t

> [email protected] test /Users/ldu020/workspace/github.com/mrdulin/jest-codelab
> jest --detectOpenHandles

 PASS  src/stackoverflow/58663681/api.tests.js
  ✓ t1 (4ms)

Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        3.883s
Ran all test suites.
© www.soinside.com 2019 - 2024. All rights reserved.