angularjs - How to trigger $onInit or $onChanges implictly in unit testing Angular component controller? -


i'm using angular 1.5.5 , jasmine test framework. have test passes:

function createcontroller(bindings) {     return $componentcontroller('mycontroller', null, bindings); }  beforeeach(inject(function (_$componentcontroller_) {     $componentcontroller = _$componentcontroller_; }));  describe('on pages updated', function () {      beforeeach(function () {         controller = createcontroller({prop1: 0, prop2: 0});         controller.$oninit(); // see have explitcitly call $oninit function     });      it('should update isselected , currentpage', function () {         expect(controller.prop1).tobe(0);         expect(controller.prop2).tobe(0);          controller.prop1= 1;         controller.prop2= 2;         controller.$onchanges(controller); // , $onchanges here          expect(controller.prop1).tobe(1);         expect(controller.prop2).tobe(2);     });  }); 

there issue in github regarding this: https://github.com/angular/angular.js/issues/14129

basically working intended, not calling $oninit or $onchanges automatically.

it makes no sense (or low sense) execute $oninit, explain it: $componentcontroller instance controllers kind of replacement $controller, instead of creating instances of controllers registered controllerprovider creates instances of controllers registered through directives (the ones satisfies component definition). so, once have instance of controller, can call manually $oninit, , lifecycle of controller, idea testing controller, not directive (and relationships).


Comments

Popular posts from this blog

Combining PHP Registration and Login into one class with multiple functions in one PHP file -

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -