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);
});
});