How to access controllerAs namespace in unit test with compiled element?

流过昼夜 提交于 2019-12-01 18:58:43

Everything works as expected :) You are just trying to access the wrong scope.

Because ngIf creates a new scope, you should access that scope (because isRendered is created on that child scope:

expect(el.children().first().scope().isRendered).toBeTruthy();

Here is the updated fiddle.


UPDATE:

You are using controllerAs, basically you get the controller's this bound to a scope property. E.g. controllerAs: 'myTestCtrl' implicitly results to $scope.myTestCtrl = this; (where this is the controller instance.

But again you where trying to access the wrong element. You need the first child-element of the wrapping <div> and then you need its isolate scope (not normal scope):

var ctrl = el.children().first().isolateScope().myTestCtrl;

Another updated fiddle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!