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