我编写了一个返回以下对象的测试控制器,
{hello: 'a', world: 'b'};
使用mocha按照方式测试
describe('Test suite', function(){
let controller;
beforeEach(window.module('app'));
beforeEach(function(){
inject(function($controller){
controller = $controller('simpleController');
console.info(controller);
});
});
afterEach(function(){
console.info("afterEach called");
});
describe('Controller', function(){
it('it should have hello', function(){
controller.should.have.property('hello')
});
it('it should have world', function(){
controller.should.have.property('world');
});
});
});
但是,在beforeEach
中第二次调用inject时,第二个测试用例失败并出现异常✖ "before each" hook for "it should have world"
Chrome 57.0.2987 (Mac OS X 10.12.1)
Error: the string "textAngular Error: A unique name is required for a Tool Definition" was thrown, throw an Error :)
如果不是我不打电话第二次注射,一切都运作良好
if (!controller) {
inject(function($controller){
controller = $controller('simpleController');
console.info(controller);
});
}
理想情况下,我希望在每个测试用例之前有一个新的控制器实例。