So I'm unit testing a component I made with Angular 1.5. For security purposes, I can't copy and paste that code here, but I can give some mocks.
It's a simple component that has some basic selection action, with an binding event when something is selected.
So the code would look like this:
angular
.module( "myModule" )
.component( "myComponent", {
template: "Some random HTML Template",
bindings: {
onSelect: "&"
},
controller: function () {
var ctrl = this;
ctrl.$onInit = init;
ctrl.selection = selection;
function init() {} function selection() {
ctrl.onSelect(ctrl.selected) }
} } );
That's the basic component. I'm trying to unit test it, with a format such as this:
describe( "Component Test", function() {
beforeEach (module( "myModule") );
var ctrl, onSelectSpy;
beforeEach (inject( function( _$componentController_) {
ctrl = {}
onSelectSpy = jasmine.createSpy("onSelect");
var $componentController = _$componentController_;
ctrl = $componentController("myComponent", null, { onSelect:
onSelectSpy});
} ) );
it ("Controller defined", function() {
ctrl.$onInit();
expect ( ctrl ).toBeDefined();
});
} );
When I try running a test that looks very similar to this, I get this error:
Unknown provider: myComponentDirectiveProvider <- myComponentDirective And it gives an angular url about the line where it fails.
Not sure why it's not getting defined and why this isn't working. I thought components were directives.
Using Angular 1.5.8 and Angular-mocks 1.5.8