I am receiving this error:
Error: [$injector:unpr] Unknown provider: checkListDirectiveProvider <- checkListDirective
why would $componentController issue an unknown directive provider error?
Looking in the source code for angular mocks, the problem is here:
return function $componentController(componentName, locals, bindings, ident) {
// get all directives associated to the component name
var directives = $injector.get(componentName + 'Directive');
Why would $injector
try and find directives, when I am registering a component?
module("app").component("checkList", new CheckListComponent());
TL;DR
(for more background information)
My test (using webpack) is structured as follows:
var mocks = require("angular");
require("angular-mocks");
require("../app.js");
require("./CheckListComponent.js");
describe("component: check list component",
function () {
var q;
var r;
beforeEach(() => mocks.module("app"));
beforeEach(inject(function (_$componentController_, $q, $rootScope) {
$componentController = _$componentController_;
q = $q;
r = $rootScope;
}));
it("show question should calculate correct answers",
function () {
var bindings = {};
var ctrl = $componentController("checkList", null, bindings);
expect(ctrl.showQuestion).toBeDefined();
});
});
I am trying to understand why this is not working. Digging into the debugger I can see that mocks.module("app")._invokeQueue
seems to contain the registered component, so why is $componentController
unable to create it?
The complete source for the component (in typescript) is:
/**
* the component wrapper.
*/
export class CheckListComponent implements ng.IComponentOptions {
controllerAs: string = "cl";
bindings: any;
controller: any;
templateUrl: string;
/**
* @constructor create a new instance of the component.
*/
constructor() {
this.bindings = { checkList: "<" };
this.controller = CheckListController;
this.templateUrl = "compliance/checklist/component";
}
}
module("app").component("checkList", new CheckListComponent());