Search code examples
angularunit-testingjasminelocal-variables

How to assign values or access value of the variables that are local to function?


I am running test for angular app through jasmine. I want to know , How to assign values or access value of the variables that are local to function?


Solution

  • You can't test it because it is gone after the call. they are scoped to the method closure,

    1. Declare them globally globallyDeclaredvariable: boolean; in your class

    2. Use them with this.globallyDeclaredvariable = true; inside your method

    3. Then you can write expect(component.globallyDeclaredvariable).toBeTruthy(); in your tests.