Skip to content

Instantly share code, notes, and snippets.

@cartant
Last active June 27, 2018 04:00
Show Gist options
  • Select an option

  • Save cartant/272151dbb3ffcc9b41ad6da258cd6080 to your computer and use it in GitHub Desktop.

Select an option

Save cartant/272151dbb3ffcc9b41ad6da258cd6080 to your computer and use it in GitHub Desktop.
import { expect } from "chai";
import { fakeSchedulers } from "rxjs-marbles/mocha";
import { timer } from "rxjs";
import * as sinon from "sinon";
describe("timer", () => {
let clock: sinon.SinonFakeTimers;
beforeEach(() => {
clock = sinon.useFakeTimers();
});
it("should be testable with fake time", fakeSchedulers(() => {
let received: number | undefined;
timer(100).subscribe(value => received = value);
clock.tick(50);
expect(received).to.be.undefined;
clock.tick(50);
expect(received).to.equal(0);
}));
afterEach(() => {
clock.restore();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment