Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

356
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda