mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-09-09 11:13:57 +08:00
Merge pull request #3875 from Nemo157/lolex
Add type definitions for lolex
This commit is contained in:
@@ -0,0 +1,116 @@
|
||||
/// <reference path="./lolex.d.ts" />
|
||||
|
||||
import lolex = require("lolex");
|
||||
|
||||
function a() {
|
||||
var clock = lolex.createClock();
|
||||
|
||||
clock.setTimeout(function () {
|
||||
console.log("The poblano is a mild chili pepper originating in the state of Puebla, Mexico.");
|
||||
}, 15);
|
||||
|
||||
// ...
|
||||
|
||||
clock.tick(15);
|
||||
}
|
||||
|
||||
function b() {
|
||||
var clock = lolex.install(window);
|
||||
|
||||
window.setTimeout(() => {}, 15); // Schedules with clock.setTimeout
|
||||
|
||||
clock.uninstall();
|
||||
|
||||
// window.setTimeout is restored to the native implementation
|
||||
}
|
||||
|
||||
function c() {
|
||||
var clock = lolex.install();
|
||||
|
||||
// Equivalent to
|
||||
// var clock = lolex.install(typeof global !== "undefined" ? global : window);
|
||||
}
|
||||
|
||||
var clock: lolex.Clock;
|
||||
|
||||
/**
|
||||
* var clock = lolex.createClock([now])
|
||||
*/
|
||||
|
||||
clock = lolex.createClock();
|
||||
clock = lolex.createClock(Date.now());
|
||||
|
||||
|
||||
/**
|
||||
* var clock = lolex.install([context[, now[, toFake]]])
|
||||
*/
|
||||
|
||||
clock = lolex.install();
|
||||
clock = lolex.install(window);
|
||||
clock = lolex.install(window, Date.now());
|
||||
clock = lolex.install(window, Date.now(), ['setTimeout', 'clearTimeout']);
|
||||
|
||||
|
||||
/**
|
||||
* var clock = lolex.install([now[, toFake]])
|
||||
*/
|
||||
|
||||
clock = lolex.install(Date.now());
|
||||
clock = lolex.install(Date.now(), ['setTimeout', 'clearTimeout']);
|
||||
|
||||
|
||||
var id: number;
|
||||
/**
|
||||
* var id = clock.setTimeout(callback, timeout)
|
||||
*/
|
||||
|
||||
id = clock.setTimeout(() => {}, 1000);
|
||||
|
||||
|
||||
/**
|
||||
* clock.clearTimeout(id)
|
||||
*/
|
||||
|
||||
clock.clearTimeout(id);
|
||||
|
||||
|
||||
/**
|
||||
* var id = clock.setInterval(callback, timeout)
|
||||
*/
|
||||
|
||||
id = clock.setInterval(() => {}, 1000);
|
||||
|
||||
|
||||
/**
|
||||
* clock.clearInterval(id)
|
||||
*/
|
||||
|
||||
clock.clearInterval(id);
|
||||
|
||||
|
||||
/**
|
||||
* var id = clock.setImmediate(callback)
|
||||
*/
|
||||
|
||||
id = clock.setImmediate(() => {});
|
||||
|
||||
|
||||
/**
|
||||
* clock.clearImmediate(id)
|
||||
*/
|
||||
|
||||
clock.clearImmediate(id);
|
||||
|
||||
|
||||
/**
|
||||
* clock.tick(time)
|
||||
*/
|
||||
|
||||
clock.tick(1000);
|
||||
|
||||
|
||||
/**
|
||||
* clock.uninstall()
|
||||
*/
|
||||
|
||||
clock.uninstall();
|
||||
Vendored
+24
@@ -0,0 +1,24 @@
|
||||
// Type definitions for lolex 1.2.1
|
||||
// Project: https://github.com/sinonjs/lolex
|
||||
// Definitions by: Wim Looman <https://github.com/Nemo157>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
declare module 'lolex' {
|
||||
export interface Clock {
|
||||
setTimeout(callback: () => any, timeout: number): number;
|
||||
setInterval(callback: () => any, timeout: number): number;
|
||||
setImmediate(callback: () => any): number;
|
||||
|
||||
clearTimeout(id: number): void;
|
||||
clearInterval(id: number): void;
|
||||
clearImmediate(id: number): void;
|
||||
|
||||
tick(ms: number): void;
|
||||
uninstall(): void;
|
||||
}
|
||||
|
||||
export function createClock(now?: number): Clock;
|
||||
|
||||
export function install(now?: number, toFake?: string[]): Clock;
|
||||
export function install(context?: any, now?: number, toFake?: string[]): Clock;
|
||||
}
|
||||
Reference in New Issue
Block a user