'I am getting TypeError: cannot stub non-existent property error while testing in angular js
I have the following code-
function SomeValidationFactory(){
function SomeValidation(){
}
SomeValidation.prototype.getValidation = function(somData){
//some methods
}
return {
create : create
}
function create(){
return new SomeValidation();
}
angular.module(valid).factory(SomeValidation, SomeFactoryValidation);
There is another class where this factory is injected and is getting used in the following method
function FooFactory(SomeFactoryValidation){
FooFactory.prototype.isValid = function(){
return FieldValidation.create().getValidation(someData);
}
function create(){
//returns FooFactory
}
return {
create: create
}
}
angular.module('foo-named').factory('name', FooFactory);
Here is the spec class
let FooNamed;
beforeEach(()=>{
inject((FooNamed,SomeValidation)=>{
FooNamed = _FooNamed_;
SomeValidation = _SomeValidation_;
});
});
}
.describe('invalid', ()=>{
it('should reject if invalid',done=>{
FooNamed.create().then(fooNamed=>{
sinon.stub(SomeValidation,'getValidation').withArgs(some_data).returns(Some_field);
fooNamed.isValid.then((valid)=>{
expect(valid).toBeTrue();
}
});
}
This is almost the code on running the test case I am getting TypeError: Cannot stub non-existent property getValidation. I tried making the stub with SomeValidation.prototype but it did not work.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
