【发布时间】:2015-07-19 02:05:53
【问题描述】:
我的角度工厂包装了外部函数:
var External = function(){};
angular.module('app', [])
.factory('ExternalWrap', function() {
Object.defineProperty(External.prototype, '$id', {
get: function() {
return this.$$id === undefined || this.$$id === null ? this.id : this.$$id;
},
set: function(value) {
this.$$id = value;
},
configurable: false,
enumerable: false
});
return External;
});
因果报应测试:
describe('test', function () {
beforeEach(module('app'));
it('should work', function() {
inject(function(ExternalWrap) {
expect(ExternalWrap).toBeDefined();
});
});
it('should work too', function() {
inject(function(ExternalWrap) {
expect(ExternalWrap).toBeDefined();
});
});
});
在第二个测试中,我收到错误TypeError: Cannot redefine property: $id。
是否可以不更改ExternalWrap 工厂进行测试?
【问题讨论】:
标签: javascript angularjs unit-testing testing karma-jasmine