I have created a spec for my library to ensure that a value is emitted at a regular interval. I am using sinonjs and have created a callback as a spy. I am using the fake timer in sinonjs to simulate an extra two intervals of 10 seconds passed. However when the test lands on the first use of the tick method, this is when the error is emitted. I produces the below error
ExpectationError: Unexpected call: getTheValue()
Expectation met: getTheValue([...]) once
Below is the code for my test
it('should emit the values at an interval', function () {
var callback = this.sandbox.spy();
var interval = this.sandbox.useFakeTimers();
this.myLib.emitValues(callback);
interval.tick(1000);
interval.tick(1000);
callback.should.have.been.calledWith('test');
});
This is my production code
_getValue() {
var value = getTheValue(this.id);
this.myListener(value);
}
emitValues(callback) {
this.myListener = callback;
this._getValue();
setInterval(() => this._getValue(), 1000);
}
Does anyone have any idea why I might be getting this error?