2
案例
当我创建rootScope
间谍,期望某种原因失败。检查一下plunkr,然后试着评论一下,然后倒车看看。茉莉花spyOn范围功能测试断裂
代码
describe('Testing', function() {
var rootScope = null
//you need to indicate your module in a test
// beforeEach(module('plunker'));
beforeEach(inject(function($rootScope, $controller) {
rootScope = $rootScope;
rootScope.value = false;
rootScope.testFn = function() {
rootScope.value = true;
}
}));
it('should modify root scope', function() {
// Creating this spy makes test fail
// Comment it outto make it pass
spyOn(rootScope, 'testFn');
expect(rootScope.value).toEqual(false);
rootScope.testFn();
expect(rootScope.value).toEqual(true);
});
});
使用spyOn(rootScope,'testFn')。和.CallThrough();为茉莉花2 –