Insight into Angular App Testing
As I delved into testing my Angular app using ng-repeat to create a table, a user brought to my attention the presence of duplicate entries. Eager to address this issue, I visually confirmed it and proceeded to craft a Protractor test.
The Inquiry
Dilemma with Variable Scoping
During the test creation process, I stumbled upon peculiar behavior in the scope that seemed unfamiliar to me.
It seemed logical that the for-loop on line 61 would have access to linkStorage
(line 38) as it resides in a higher scope. The console indicated successful addition of objects via the for-loop within the promise at line 47.
However, when attempting to perform the confirmation loop outside the promise, such as before the expect
statement...
...linkStorage
appeared as an empty object.
No nested key-value pairs could be identified upon iterating over the object; it was undeniably void of any data.
Pondering the Question (in short)
What is causing the linkStorage
object to populate inside the then statement, but not before the expectation?