Jasmine: Set controller property on initialization, Angular 1.5

16 views
Skip to first unread message

Abubakr Dar

unread,
Aug 24, 2016, 9:36:42 AM8/24/16
to Jasmine

Controller

function SomeController(someService) {
  const $ctrl = this;

  activate();

  function activate() {
    someService.retrieveSomeData($ctrl.criteria).then(doSomething);
  }

  function doSomething(response) {
    $ctrl.result = response.data;
  }
}

Test

describe('SomeController', () => {

  beforeEach(module('myModule'));

  let $controller;

  beforeEach(inject((_$controller_,) => {
    $controller = _$controller_;
  }));

 it('tests $controller properties', () => {
    const $scope = {};
    const controller = $controller('SomeController', { $scope });
  });
});

Here I want to sent $ctrl.criteria while initializing my controller so I can test $ctrl.resultafterwards. As you can, activate() method is fired upon initialization, so I can't set criteria after initialization.

Reply all
Reply to author
Forward
0 new messages