【发布时间】:2015-07-18 14:59:16
【问题描述】:
如果您有多个beforeEach,它们会一直一个接一个地运行吗?
beforeEach(function() {});
beforeEach(function() {});
beforeEach(function() {});
beforeEach(function() {});
beforeEach(function() {});
看来他们会的。我尝试用我的代码对其进行测试:
describe('Directive: Statement', function() {
var el, scope, statements;
beforeEach(module('simulatedSelves'));
beforeEach(module('templates'));
beforeEach(inject(function($compile, $rootScope) {
console.log(1);
scope = $rootScope.$new();
statements = [];
scope.statement = {
text: 'test',
arr: []
};
scope.statement.parent = statements;
statements.push(scope.statement);
el = angular.element('<statement statement=statement></statement>');
$compile(el)(scope);
scope.$digest();
}));
beforeEach(function() {
var counter = 0;
console.log(2);
for (var i = 0; i < 1000000; i++) {
counter++;
}
console.log(counter);
});
beforeEach(function() {
console.log(3);
});
it('test statement has correct properties', function() {
// stuff
});
});
它记录:
1
2
1000000
3
由于beforeEach 和长for 循环在记录3 之前记录其内容,我认为beforeEach 同步运行。这是真的吗?
【问题讨论】:
标签: javascript jasmine