Javascript 使用RxJS 5去BounceTime进行AngularJS测试

Javascript 使用RxJS 5去BounceTime进行AngularJS测试,javascript,angularjs,testing,jasmine,rxjs,Javascript,Angularjs,Testing,Jasmine,Rxjs,我有一个呈现标签和输入的组件 在$postLink上,我向输入焦点添加一个over,如果触发了焦点事件,我将内部变量focused设置为true $postLink() { Rx.Observable.fromEvent(myInputElement, 'focus') .debounceTime(200) .subscribe(() => { this.focused = true; this.$scope.$evalAsync(

我有一个呈现标签和输入的组件 在$postLink上,我向输入焦点添加一个over,如果触发了焦点事件,我将内部变量
focused
设置为
true

$postLink() { 
    Rx.Observable.fromEvent(myInputElement, 'focus')
      .debounceTime(200)
      .subscribe(() => {
      this.focused = true;
      this.$scope.$evalAsync();
    });
}
在我的测试文件(我使用的是Jasmine)中,我有如下内容:

it('must set "focused" to true when input get focused', () => {
  // The setupTemplate return a angular.element input, my component controller and scope
  const { input, controller, parentScope } = setupTemplate();
  input[0].dispatchEvent(new Event('focus'));
  $timeout.flush(600);
  parentScope.$digest();
  expect(controller.focused).toBe(true);
});
但我的测试失败了

如果我从我的组件方法中删除
去BounceTime
,则测试通过


我能做些什么来模拟去BounceTime?

感谢@martin,我的测试是绿色的

我刚刚在回调中添加了一个done,并在一个setTimeout

it('must set "focused" to true when input get focused', (done) => {
  const { input, controller, parentScope } = setupTemplate();
  input[0].dispatchEvent(new Event('focus'));
  setTimeout(() => {
    expect(controller.focused).toBe(true);
    done();
  }, 300);
});

感谢@martin,我的测试是绿色的

我刚刚在回调中添加了一个done,并在一个setTimeout

it('must set "focused" to true when input get focused', (done) => {
  const { input, controller, parentScope } = setupTemplate();
  input[0].dispatchEvent(new Event('focus'));
  setTimeout(() => {
    expect(controller.focused).toBe(true);
    done();
  }, 300);
});

测试是异步的,因此您可以使用
it(“…”,done=>{})
然后调用
done()
manually@martinTHAAANKS!!!,这就是它=dd测试是异步的,因此您可以使用
It('…',done=>{})
然后调用
done()
manually@martinTHAAANKS!!!,就是这样