I'm trying to test view of my controller but I cannot get this to work.
When I try simple template as<h1>test</h1>
it works but when template is using controllerAs
syntax I get Expected undefined to contain 'test'.
I did some research and transcludeControllers
should deal with this but it don't. My test look 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'm using AngularJS 1.6.3
and Jasmine/Karma combo.