I have a method which is being called using a d3 timer
. Whenever the method is called, the method emits an object with a couple of values.
One of the values increases over time. I would like to write a test to check whether the values are in the ascending order or not (i.e., increasing over time or not).
So, to tackle this, In my test, I subscribe to the event emitter and inside the subscription, I am pushing the object which I receive into a local array. And then, I am expecting the array[i]
to be less than the array[i+1]
. I think my logic is perfectly correct but I am not sure why I am getting an error from Jasmine saying that the spec has no expectations
even though I have one.
Here is the code:
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 });
}
}
The Jasmine Spec:
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);
}
});
}));
Am I doing anything wrong here? How can I tackle such kind of a scenario? Please guide me in a right direction.
Thank you.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…