Search code examples
javascriptangularjsng-showangularjs-ng-show

Angular ng-show handling undefined variables


I've two directives which display based on a variable being configured.

This visually worked but during acceptance tests I found a problem. I attempted to assert that if the <settingElement> hasn't been clicked (configuring the var selected), neither directive is displayed. The test passed for <directiveA> but failed for <directiveB> leaving me a little confused.

An example of the code is below:

<settingElement ng-click="selected = trueOrFalse()"></settingElement>

<directiveA ng-show="selected"></directiveA>
<directiveB ng-show="!selected"></directiveB>

Solution

  • Success! At least kinda, visually the code works so instead of testing for isDisplayed I simply asserted that the height and width are both 0... not ideal but works.