Oli*_*ryn 16 javascript unit-testing jasmine karma-runner angular
我在我的开发盒上运行Karma/Jasmine/Angular 2.0测试.就在最近,我的开发盒上的Jasmine决定开始运行我的测试三次.是的,每次都是三次.
在第一次运行时,一切都按预期通过.但是,在第二次和第三次通过时,所有相同的事情都失败了.它总是承认有7个测试,但运行21个,10个失败(一级数学窗外)????
对于带有SauceLabs的Travis,这也失败了.(注意:通过3次测试链接到旧版本,但运行9次,5次失败???)
我有一个截图,karma.conf.js文件,以及一个启动整个事情的套件.非常感谢任何帮助.
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 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...
});
Run Code Online (Sandbox Code Playgroud)
不确定这是否相关,但在所有错误发生之前,Jasmine调用堆栈较小(左,观察滚动条).错误开始后,堆栈只会重复调用相同的函数(右键,观察滚动条).
在我的测试中,Nanobar和Conductor spec文件是完全独立的.但是,您可以看到套件阵列包含来自Nanobar和Conductor规范的内容.不知怎的,Jasmine将这两个spec文件混合在一起(在一切开始失败之后),并导致我的describe()语句在发布到控制台时没有任何意义.
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
}
})
}
Run Code Online (Sandbox Code Playgroud)
首先,这些测试是随机运行的。如果你在任何测试用例中传递一些数据,如果你认为你可以断言这是不可能的。
您必须在每个测试用例之前声明数据,以便所有测试用例都能获取数据。所有测试用例独立运行。
如果您使用数组或对象,则必须在深度克隆后使用它,因为数组和对象作用于引用。如果您操作任何值,它也会更改原始数组。
在大多数情况下,如果测试失败,则您在测试用例中传递的数据可能存在错误。
| 归档时间: |
|
| 查看次数: |
1212 次 |
| 最近记录: |