【发布时间】:2016-06-02 14:47:39
【问题描述】:
当我在嵌套描述测试套件中使用简单的beforeAll() 而不是beforeEach() 时,我很难理解为什么我的代码不起作用以及为什么测试会失败?这是一个概述我的问题的小例子:
describe("myService", function() {
// Basic services
// Some variables
beforeEach(module('app')); // Invoke the module
beforeEach(function(){
// Inject the services
inject(function(_myService_) {
myService = _myService_;
});
});
/************************ Add more unit tests here ************************/
describe("myFunction", function() {
describe("calls function with one set of input paramenters", function() {
//beforeAll(function() {
beforeEach(function() { // <-- Why this works but beforeAll doesn't???
// Call myFunction with different parameters
result = myService.myFunction(parametersType_1);
});
it("should do tests on result (the return from the function)", function() {
});
});
describe("calls function with other set of input paramenters", function() {
//beforeAll(function() {
beforeEach(function() { // <-- Why this works but beforeAll doesn't???
// Call myFunction with different parameters
result = myService.myFunction(parametersType_2);
});
it("should do tests on result (the return from the function)", function() {
});
});
});
【问题讨论】:
标签: angularjs unit-testing jasmine