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

227
Visualizações
Angular unit testing a function variable

I want to test a variable function of a void function. How can I get that local variable in the test? function:

save(){
const stringTest="test";
}

test:

test("variable should be equal to "test" ", () => {
    component.save();
    //test stringTest from save function that is equal to "test"
  });
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

First, you cannot access a primitive local variable inside a function after you call it (at least not in conventional ways). The reason may seem obvious, still it is worth pointing out that local variables are released when javascript's runtime finds them unusable.

Second, you do not want to access locals. Declaring a local variable is a kind of a statement that you want that variable to participate in some internal flow or algorithm. After all, not everything should be exposed to the outside world. Every system encapsulates internal behavior to some extent, and a function is also a system (a very small one, though).

Your function, save(), has neither input (arguments) nor output (return value, side effect), so nothing to test here...

over 4 years ago · Santiago Trujillo Relatório
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