A. *_*Lau 11 javascript testing jestjs
所以,如果我把console.log里面test的console.log将测试如后出现
authentication.spec.js
register
? should be able to insert (128ms)
? should fail because of duplicate (100ms)
? should have user id assigned (1ms)
login
? should be able to login for correct user (117ms)
? should fail for incorrect user (14ms)
console.log tests/unit/authentication.spec.js:110
we can see a message
Run Code Online (Sandbox Code Playgroud)
我希望看到的是:
authentication.spec.js
register
? should be able to insert (128ms)
? should fail because of duplicate (100ms)
? should have user id assigned (1ms)
login
? should be able to login for correct user (117ms)
console.log tests/unit/authentication.spec.js:110
we can see a message
? should fail for incorrect user (14ms)
Run Code Online (Sandbox Code Playgroud)
所以console.log应该? should be able to login for correct user在这种情况下出现
当我使用摩卡时我正在使用 mocha-logger
据我所知,这是不可能的,虽然有几个地方可以寻找更多信息(不是开箱即用):
Jest允许使用自定义记者:https://jestjs.io/docs/en/configuration.html#reporters-array-modulename-modulename-options,因此您可以编写自己的记者并以不同方式显示输出.目前虽然您没有获得单独测试的更新,但只是测试套装,这是由Dan Abramov创建的问题:https://github.com/facebook/jest/issues/6616.
从上面的github线程 - 现在的Reporter接口看起来像:
export default class BaseReporter {
onRunStart(results: AggregatedResult, options: ReporterOnStartOptions) {}
// these are actually for the test suite, not individual test results
onTestStart(test: Test) {}
onTestResult(test: Test, testResult: TestResult, results: AggregatedResult) {}
onRunComplete(contexts: Set<Context>, results: AggregatedResult ): ?Promise<void> {}
}
Run Code Online (Sandbox Code Playgroud)
我没有找到一种预定义的方法来将参数从test传递到testResult对象中.因此,您主要限于根据测试名称记录信息.下面是对象testResult内部属性的示例testResult:
testResults:
[ { ancestorTitles: [Array],
duration: 5,
failureMessages: [],
fullName: 'add should add two numbers',
location: null,
numPassingAsserts: 0,
status: 'passed',
title: 'should add two numbers' } ],
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,这是标准记者使用的所有信息:测试名称,持续时间,状态.作为参考,默认记者在这里:https://github.com/facebook/jest/blob/7b7fd01350/packages/jest-cli/src/reporters/default_reporter.js
是的,您可以将其记录下来。您可能需要添加--verbose false到 package.json "test";
前任: "scripts": {
"test": "jest --watch --verbose false"
}
| 归档时间: |
|
| 查看次数: |
3262 次 |
| 最近记录: |