Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

350
Views
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.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!