我正在我的开发箱上运行 Karma/Jasmine/Angular 2.0 测试。就在最近,我的开发箱上的 Jasmine 决定开始运行我的测试 3 次。是的,每次正好三遍。
在第一次运行时,一切都按预期进行。但是,在第二次和第三次通过时,所有相同的事情都失败了。它总是承认有 7 次测试,但运行 21 次,10 次失败(窗外一年级数学)????
这也是fails on Travis与 SauceLabs。 ( 注意: 链接到带有 3 次测试的旧版本,但运行了 9 次,并且 5 次失败???)
我有一个屏幕截图、karma.conf.js 文件和一个启动整个事情的套件。任何帮助将不胜感激。
罪魁祸首 [TypeScript](删除这个并在我的开发盒上解决了问题):
Full source
describe('From the Conductor Service', () => {
let arr: Array<ComponentStatusModel> = null;
let svc: ConductorService = null;
beforeEach(() => {
arr = [/* Inits the array*/];
svc = new ConductorService();
});
describe('when it is handed a container to hold objects which need to be loaded', () => {
// More passing tests...
/// vvvvv The culprit !!!!!
describe('then when you need to access the container', () => {
beforeEach(() => {
svc.loadedContainer = arr;
});
it('it should always be available', () => {
assertIsLocalDataInTheService(arr, svc.loadedContainer);
});
});
/// ^^^^^ End of culprit !!!!!
});
// More passing tests...
});
失败的测试:浏览器截图:
不确定这是否相关,但在所有错误发生之前,Jasmine 调用堆栈较小(左侧,观察滚动条)。错误开始后,堆栈会随着重复调用相同的函数而变大(右,观察滚动条)。
套件堆栈错误:
在我的测试中,纳米棒和导体规范文件是完全分开的。但是,您可以看到套件阵列包含来自 Nanobar 和 Conductor 规范的内容。 Jasmine 不知何故将这两个规范文件混合在一起(在一切开始失败之后),并导致我的 describe() 语句在发布到控制台时没有任何意义。
简化的 karma.conf.js:
Full source
module.exports = function (config) {
config.set({
autoWatch: false,
basePath: '.',
browsers: ['Chrome'],
colors: true,
frameworks: ['jasmine'],
logLevel: config.LOG_INFO,
port: 9876,
reporters: ['coverage', 'progress'],
singleRun: true,
coverageReporter: {
// Code coverage config
},
files: [
// Loads everything I need to work
],
plugins: [
'karma-chrome-launcher',
'karma-coverage',
'karma-jasmine'
],
preprocessors: {
'app/**/*.js': ['coverage']
},
proxies: {
// Adjust the paths
}
})
}
最佳答案
您可以尝试在每个测试文件的第一个断言中刷新浏览器吗?
尝试这个:
browser.restart();
我有同样的问题,这为我解决了。
关于javascript - Jasmine 运行测试 3 次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35710877/