我有一个方法,它是用d3 timer
来调用的.无论何时调用该方法,该方法都会发出一个带有几个值的对象.
所以,为了解决这个问题,在我的测试中,我订阅了事件emits 器,在订阅中,我将接收到的对象推送到一个本地数组中.然后,我希望array[i]
比array[i+1]
小.我认为我的逻辑是完全正确的,但我不确定为什么Jasmine说the spec has no expectations
是错误的,尽管我有一个.
以下是代码:
let x = d3.timer((elapsed) => {
this.method(); // call the function
if(elapsed >= 500) {
x.stop(); // stops the timer.
}
});
method(elapsed) {
// do something
if(elapsed > 500) {
this.output.emit({x: somevalue, y: somevalue, f: increasingvalue });
}
}
茉莉花规格:
it('my spec', inject([JumpService], (service: JumpService) =>{
array = [];
//service calls the method
service.output.subscribe(e => {
array.push(e);
// A console statement here will give me the length and the object pushed.
for(let i = 0; i< array.length - 1; i++) {
expect(array[i].f).toBeLessThan(array[i+1].f);
}
});
}));
我做错什么了吗?我如何应对这种情况?请把我引向正确的方向.
非常感谢.