我有一个使用d3 timer
. 每当调用该方法时,该方法都会发出一个带有几个值的对象。其中一个值随时间增加。我想编写一个测试来检查这些值是否按升序排列(即,是否随时间增加)。
因此,为了解决这个问题,在我的测试中,我订阅了事件发射器,在订阅中,我将收到的对象推送到本地数组中。然后,我期望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);
}
});
}));
我在这里做错什么了吗?我该如何应对这种情况?请指导我正确的方向。
谢谢你。