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

225
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
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