Я создал простой класс для опроса Event Emitter
из Nodejs Например:
import EventEmitter from "events";
import config from "../config";
export class Poller extends EventEmitter {
constructor(private timeout: number = config.pollingTime) {
super();
this.timeout = timeout;
}
poll() {
setTimeout(() => this.emit("poll"), this.timeout);
}
onPoll(fn: any) {
this.on("poll", fn); // listen action "poll", and run function "fn"
}
}
Но я не знаю, как написать правильный тест для Class
.Это мой юнит-тест
import Sinon from "sinon";
import { Poller } from "./polling";
import { expect } from "chai";
describe("Polling", () => {
it("should emit the function", async () => {
let spy = Sinon.spy();
let poller = new Poller();
poller.onPoll(spy);
poller.poll();
expect(spy.called).to.be.true;
});
});
Но он всегда ложный
1) Polling
should emit the function:
AssertionError: expected false to be true
+ expected - actual
-false
+true
Скажите, пожалуйста, что не так с моим тестовым файлом.Большое спасибо!