我正在使用 karma viewport npm包来通过
jasmine
测试规范来设置chrome浏览器的 viewport
。我遵循了上面提供的链接中的指南。这很简单,但是不知道为什么我无法使它工作。
这是我的 karma.conf.js 文件。
module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['jasmine', '@angular/cli', 'viewport'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-remap-istanbul'),
require('@angular/cli/plugins/karma'),
require('karma-viewport')
],
files: [
{ pattern: './src/test.ts', watched: false }
],
preprocessors: {
'./src/test.ts': ['@angular/cli']
},
mime: {
'text/x-typescript': ['ts','tsx']
},
remapIstanbulReporter: {
reports: {
html: 'coverage',
lcovonly: './coverage/coverage.lcov'
}
},
angularCli: {
config: './angular-cli.json',
environment: 'dev'
},
reporters: config.angularCli && config.angularCli.codeCoverage
? ['progress', 'karma-remap-istanbul']
: ['progress'],
htmlReporter: {
outputFile: 'unit_test/report.html',
//Optional
pageTitle: 'Unit Tests',
subPageTitle: 'This file includes all unit test cases segmented according to their suites.',
groupSuites: true
},
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false
});
};
我正在尝试设置视口的测试规范
it('In mobile view, there should be three separate tabs to show daily, monthly and yearly savings', fakeAsync(() => {
component.scrollToCalc();
// approximate time required to load the calculator with animation
tick(1000);
fixture.detectChanges();
viewport.set(200, 300); // viewport variable throws error
fixture.detectChanges();
}));
编译器显示的错误信息为:
找不到名为“viewport”的变量。
我认为我不需要在TestBed
配置中进行任何其他更改才能使其正常工作。不知何故,在我的spec
文件中未公开viewport
变量。