Files
DefinitelyTyped/types/lolex/lolex-tests.ts
Andrew Moss c61b1db6eb lolex: Fix install() method parameters (#27193)
lolex.install() can take a Date or a number (see https://github.com/sinonjs/lolex#var-clock--lolexinstallconfig)

- [x] Use a meaningful title for the pull request. Include the name of the package modified.
- [x] Test the change in your own code. (Compile and run.)
- [x] Add or edit tests to reflect the change. (Run with `npm test`.)
- [x] Follow the advice from the [readme](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/README.md#make-a-pull-request).
- [x] Avoid [common mistakes](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/README.md#common-mistakes).
- [x] Run `npm run lint package-name` (or `tsc` if no `tslint.json` is present).

If changing an existing definition:
- [x] Provide a URL to documentation or source code which provides context for the suggested changes: https://github.com/sinonjs/lolex#var-clock--lolexinstallconfig
- [x] Increase the version number in the header if appropriate.
- [x] If you are making substantial changes, consider adding a `tslint.json` containing `{ "extends": "dtslint/dt.json" }`.
2018-07-12 00:47:06 -07:00

89 lines
2.5 KiB
TypeScript

import lolex = require("lolex");
let browserClock: lolex.BrowserClock = lolex.createClock() as lolex.BrowserClock;
let nodeClock: lolex.NodeClock = lolex.createClock() as lolex.NodeClock;
browserClock = lolex.createClock<lolex.BrowserClock>();
nodeClock = lolex.createClock<lolex.NodeClock>();
lolex.createClock<lolex.BrowserClock>(7);
lolex.createClock<lolex.BrowserClock>(new Date());
lolex.createClock<lolex.BrowserClock>(7, 9001);
lolex.createClock<lolex.BrowserClock>(new Date(), 9001);
lolex.createClock<lolex.NodeClock>(7);
lolex.createClock<lolex.NodeClock>(new Date());
lolex.createClock<lolex.NodeClock>(7, 9001);
lolex.createClock<lolex.NodeClock>(new Date(), 9001);
lolex.install<lolex.BrowserClock>({
advanceTimeDelta: 20,
loopLimit: 10,
now: 0,
shouldAdvanceTime: true,
target: {},
toFake: ["setTimeout", "nextTick", "hrtime"]
});
lolex.install<lolex.BrowserClock>({
advanceTimeDelta: 20,
loopLimit: 10,
now: new Date(0),
shouldAdvanceTime: true,
target: {},
toFake: ["setTimeout", "nextTick", "hrtime"]
});
const browserNow: number = browserClock.now;
const browserDate: Date = new browserClock.Date();
const nodeNow: number = nodeClock.now;
const nodeDate: Date = new nodeClock.Date();
const browserTimeout: number = browserClock.setTimeout(() => {}, 7);
const browserInterval: number = browserClock.setInterval(() => {}, 7);
const browserImmediate: number = browserClock.setImmediate(() => {});
const nodeTimeout: lolex.NodeTimer = nodeClock.setTimeout(() => {}, 7);
const nodeInterval: lolex.NodeTimer = nodeClock.setInterval(() => {}, 7);
const nodeImmediate: lolex.NodeTimer = nodeClock.setImmediate(() => {});
browserClock.clearTimeout(browserTimeout);
browserClock.clearInterval(browserInterval);
browserClock.clearImmediate(browserImmediate);
nodeClock.clearTimeout(nodeTimeout);
nodeClock.clearInterval(nodeInterval);
nodeClock.clearImmediate(nodeImmediate);
browserClock.tick(7);
browserClock.tick("08");
nodeClock.tick(7);
nodeClock.tick("08");
browserClock.next();
nodeClock.next();
browserClock.runAll();
nodeClock.runAll();
browserClock.runToLast();
nodeClock.runToLast();
browserClock.setSystemTime();
browserClock.setSystemTime(7);
browserClock.setSystemTime(new Date());
nodeClock.setSystemTime();
nodeClock.setSystemTime(7);
nodeClock.setSystemTime(new Date());
nodeClock.nextTick(() => undefined);
browserClock.uninstall();
nodeClock.uninstall();
// Clocks should be typed to have unbound method signatures that can be passed around
const { clearTimeout } = browserClock;
clearTimeout(0);