Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

355
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda