为什么 Karma 会跳过我的有效单元测试?
Why is Karma is skipping over my valid unit test?
我在 Angular 10 项目中与 Karma 合作。我正在尝试测试选择器,我可以通过 运行ning npm run test-report
看到文件显示在所有文件列表中,但是当我 运行 测试时我可以看到文件是跳过。我什至尝试在 describe 之前放一个 f
并且 karma 仍然跳过它。此测试与我 运行 的其他测试几乎完全相同,因此令人费解。请参阅下面的相关 selector.spec 文件代码和我的业力配置。
import { SupportState } from './reducers';
import { supportConfig } from './support.constant';
import * as selectors from './support.selectors';
fdescribe('SupportSelectors', () => {
let supportConfiguration;
let myFaqs;
let state: SupportState;
beforeEach(() => {
supportConfiguration = supportConfig;
myFaqs = {
answer: "<p>Once signed in to Member Online Services, you can find out if you have coverage for Durable Medica;",
question: "Am I covered for Durable Medical Equipment (DME) such as breast pumps, sleep apnea machines and orthotics???",
id: 15,
name: "Benefits"
}
state = {
config: supportConfiguration,
faqs: myFaqs,
category: myFaqs.name,
error: undefined
};
it('should return the configuration for Support', () => {
expect(selectors.selectSupportConfig.projector(state)).toEqual(supportConfiguration);
});
it('should return faqs', () => {
expect(selectors.selectSupportFAQs.projector(state)).toEqual(myFaqs);
});
it('should return category', () => {
expect(selectors.selectSupportFAQCategory.projector(state)).toEqual(myFaqs.name);
});
});
});
Karma.conf.js
// Karma configuration file, see link for more information
// https://karma-runner.github.io/1.0/config/configuration-file.html
module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['jasmine', '@angular-devkit/build-angular'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage-istanbul-reporter'),
require('@angular-devkit/build-angular/plugins/karma'),
],
client: {
clearContext: false, // leave Jasmine Spec Runner output visible in browser
},
coverageIstanbulReporter: {
dir: require('path').join(__dirname, './coverage/member-portal'),
reports: ['html', 'lcovonly', 'text-summary'],
fixWebpackSourcePaths: true,
},
reporters: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
browserNoActivityTimeout: 60000,
browserDisconnectTimeout: 60000,
autoWatch: true,
browsers: ['Chrome', 'ChromeHeadless'],
singleRun: false,
customLaunchers: {
ChromeHeadless: {
base: 'Chrome',
flags: ['--headless', '--disable-gpu', '--no-sandbox', '--remote-debugging-port=9222'],
},
},
restartOnFileChange: true,
});
};
看起来您的 it()
期望嵌套在您的 beforeEach
块中。他们应该是 beforeEach
的同行,或者是最近的 describe
.
的直属
我在 Angular 10 项目中与 Karma 合作。我正在尝试测试选择器,我可以通过 运行ning npm run test-report
看到文件显示在所有文件列表中,但是当我 运行 测试时我可以看到文件是跳过。我什至尝试在 describe 之前放一个 f
并且 karma 仍然跳过它。此测试与我 运行 的其他测试几乎完全相同,因此令人费解。请参阅下面的相关 selector.spec 文件代码和我的业力配置。
import { SupportState } from './reducers';
import { supportConfig } from './support.constant';
import * as selectors from './support.selectors';
fdescribe('SupportSelectors', () => {
let supportConfiguration;
let myFaqs;
let state: SupportState;
beforeEach(() => {
supportConfiguration = supportConfig;
myFaqs = {
answer: "<p>Once signed in to Member Online Services, you can find out if you have coverage for Durable Medica;",
question: "Am I covered for Durable Medical Equipment (DME) such as breast pumps, sleep apnea machines and orthotics???",
id: 15,
name: "Benefits"
}
state = {
config: supportConfiguration,
faqs: myFaqs,
category: myFaqs.name,
error: undefined
};
it('should return the configuration for Support', () => {
expect(selectors.selectSupportConfig.projector(state)).toEqual(supportConfiguration);
});
it('should return faqs', () => {
expect(selectors.selectSupportFAQs.projector(state)).toEqual(myFaqs);
});
it('should return category', () => {
expect(selectors.selectSupportFAQCategory.projector(state)).toEqual(myFaqs.name);
});
});
});
Karma.conf.js
// Karma configuration file, see link for more information
// https://karma-runner.github.io/1.0/config/configuration-file.html
module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['jasmine', '@angular-devkit/build-angular'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage-istanbul-reporter'),
require('@angular-devkit/build-angular/plugins/karma'),
],
client: {
clearContext: false, // leave Jasmine Spec Runner output visible in browser
},
coverageIstanbulReporter: {
dir: require('path').join(__dirname, './coverage/member-portal'),
reports: ['html', 'lcovonly', 'text-summary'],
fixWebpackSourcePaths: true,
},
reporters: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
browserNoActivityTimeout: 60000,
browserDisconnectTimeout: 60000,
autoWatch: true,
browsers: ['Chrome', 'ChromeHeadless'],
singleRun: false,
customLaunchers: {
ChromeHeadless: {
base: 'Chrome',
flags: ['--headless', '--disable-gpu', '--no-sandbox', '--remote-debugging-port=9222'],
},
},
restartOnFileChange: true,
});
};
看起来您的 it()
期望嵌套在您的 beforeEach
块中。他们应该是 beforeEach
的同行,或者是最近的 describe
.