如何让
ng test --browsers=ChromeHeadless
显示spec.ts文件的describe()
和it()
中的描述?
例如:
ng test --include=src/app/interval/interval.spec.ts
在 Chrome 浏览器中显示此内容:
finished in 0.039s
1 spec, 0 failures, randomized with seed 41004
interval
should emit every millisecond
地点:
interval
should emit every millisecond
来自我的interval.spec.ts中的“describe()”和“it()”中的描述:
import { interval } from 'rxjs';
import { testScheduler } from '../test_scheduler';
import { take } from 'rxjs/operators';
describe('interval', () => {
it('should emit every millisecond', () => {
testScheduler.run((helpers) => {
const { expectObservable } = helpers;
const numbers$ = interval(1).pipe(take(2));
expectObservable(numbers$).toBe('-0(1|)', {'0': 0, '1': 1});
});
});
});
但是,我想要的输出是:
interval
should emit every millisecond
运行时不出现:
ng test --browsers=ChromeHeadless --no-watch --progress --include=src/app/interval/interval.spec.ts
实际产量:
✔ Browser application bundle generation complete.
29 12 2023 07:33:28.830:INFO [karma-server]: Karma v6.4.2 server started at http://localhost:9876/
29 12 2023 07:33:28.833:INFO [launcher]: Launching browsers ChromeHeadless with concurrency unlimited
29 12 2023 07:33:28.842:INFO [launcher]: Starting browser ChromeHeadless
29 12 2023 07:33:29.577:INFO [Chrome Headless 117.0.5938.132 (Linux x86_64)]: Connected on socket LwJzp9zIOKI1y83KAAAB with id 33092643
Chrome Headless 117.0.5938.132 (Linux x86_64): Executed 1 of 1 SUCCESS (0.002 secs / 0.01 secs)
TOTAL: 1 SUCCESS
版本: "@angular/cli": "^17.0.8", "茉莉花核心": "~5.1.0", "业力": "~6.4.0", "karma-chrome-launcher": "~3.2.0", "karma-jasmine": "~5.1.0"
您需要 karma-jasmine-html-reporter 插件。
首先使用
npm
安装它
npm install karma-jasmine-html-reporter --save-dev
然后在里面定义它
karma.conf.js
module.exports = function(config) {
config.set({
frameworks: ['jasmine'],
plugins: [
require('karma-jasmine'),
require('karma-jasmine-html-reporter')
],
...