How to check a view that uses controllerAs in AngularJS
I am trying to test the view of my controller, but I cannot get it to work. When I try a simple template as <h1>test</h1>
it works, but when the template uses the syntax controllerAs
I get Expected undefined to contain 'test'.
I have done some research and transcludeControllers
have to deal with it, but it is not. My test looks like this:
it('should show test section', () => {
let candidatesCtrl = $controller('CandidatesController', mock);
candidatesCtrl.loading = false;
let scope = $rootScope.$new();
let linkFn = $compile('<h1 ng-if="!candidatesCtrl.loading">test</h1>');
let view = linkFn(scope,
undefined, {
transcludeControllers: {
CandidatesController: {
instance: candidatesCtrl
}
}
});
scope.$digest();
let templateAsHtml = view.html();
expect(templateAsHtml).toContain('test');
});
How do I get this to work? I am using AngularJS 1.6.3
and Jasmine / Karma commands .
+3
source to share
No one has answered this question yet
See similar questions:
or similar: