0
난 각도 구성 요소가 있고 비동기 메서드를 호출 한 후 상태를 테스트하고 싶습니다. 어떻게해야합니까? 내 방법 doSomething는 약속을 반환하지 않습니다!비동기 구성 요소 메서드 테스트
angular.module('myModule').component('myComponent', {
template: '<p></p>',
controller: function($q) {
this.state = 1;
this.doSomething: function() {
var that = this;
setTimeout(function() { that.state = 2; }, 50);
}
}
});
테스트
describe('Test', function() {
var ctrl = null;
beforeEach(module('myModule'));
beforeEach(inject(function(_$componentController_) {
ctrl = _$componentController_('myComponent', null, {});
}));
it('should be 2', function() {
ctrl.doSomething();
expect(ctrl.state).toBe(2);
});
});