-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[@sinonjs/fake-timers] Add definitions (#3727)
- Loading branch information
1 parent
5175c53
commit d340a3d
Showing
2 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
definitions/npm/@sinonjs/fake-timers_v6.x.x/flow_v0.104.x-/fake-timers_v6.x.x.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
declare module '@sinonjs/fake-timers' { | ||
declare opaque type ImmediateID; | ||
|
||
declare type FakeMethod = | ||
| 'setTimeout' | ||
| 'clearTimeout' | ||
| 'setImmediate' | ||
| 'clearImmediate' | ||
| 'setInterval' | ||
| 'clearInterval' | ||
| 'Date' | ||
| 'nextTick' | ||
| 'hrtime' | ||
| 'requestAnimationFrame' | ||
| 'cancelAnimationFrame' | ||
| 'requestIdleCallback' | ||
| 'cancelIdleCallback'; | ||
|
||
declare type InstallConfig = {| | ||
target?: { ... }, | ||
now?: number | Date, | ||
toFake?: FakeMethod[], | ||
loopLimit?: number, | ||
shouldAdvanceTime?: boolean, | ||
advanceTimeDelta?: number, | ||
|}; | ||
|
||
declare type Timers = {| | ||
setTimeout: typeof setTimeout, | ||
clearTimeout: typeof clearTimeout, | ||
setInterval: typeof setInterval, | ||
clearInterval: typeof clearInterval, | ||
setImmediate: typeof setImmediate, | ||
clearImmediate: typeof clearImmediate, | ||
Date: typeof Date, | ||
|}; | ||
|
||
declare type Clock = {| | ||
...Timers, | ||
requestAnimationFrame: typeof requestAnimationFrame, | ||
cancelAnimationFrame: typeof cancelAnimationFrame, | ||
requestIdleCallback: typeof requestIdleCallback, | ||
cancelIdleCallback: typeof cancelIdleCallback, | ||
now: number, | ||
timeouts: { ... }, | ||
loopLimit: number, | ||
countTimers(): number, | ||
hrtime: typeof process.hrtime, | ||
nextTick: typeof process.nextTick, | ||
performance?: { now: typeof performance.now, ... }, | ||
tick(time: number | string): void, | ||
tickAsync(time: number | string): Promise<void>, | ||
next(): void, | ||
nextAsync(): Promise<void>, | ||
reset(): void, | ||
runAll(): void, | ||
runAllAsync(): Promise<void>, | ||
runMicrotasks(): void, | ||
runToFrame(): void, | ||
runToLast(): void, | ||
runToLastAsync(): Promise<void>, | ||
setSystemTime(now?: number | Date): void, | ||
uninstall(): void, | ||
Performance: typeof Performance, | ||
|}; | ||
|
||
declare type FakeTimers = { | ||
timers: Timers, | ||
createClock(now?: number | Date, loopLimit?: number): Clock, | ||
install(config?: InstallConfig): Clock, | ||
withGlobal(global: { ... }): FakeTimers, | ||
... | ||
}; | ||
|
||
declare module.exports: FakeTimers; | ||
} |
32 changes: 32 additions & 0 deletions
32
definitions/npm/@sinonjs/fake-timers_v6.x.x/flow_v0.104.x-/test_fake-timers_v6.x.x.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// @flow | ||
import { describe, it } from 'flow-typed-test'; | ||
import FakeTimers from '@sinonjs/fake-timers'; | ||
|
||
describe('@sinonjs/fake-timers', () => { | ||
it('install', () => { | ||
FakeTimers.install({ | ||
target: global, | ||
now: 150, | ||
loopLimit: 250, | ||
}); | ||
|
||
// $ExpectError | ||
FakeTimers.install(true); | ||
}); | ||
|
||
it('clock', () => { | ||
const clock = FakeTimers.install(); | ||
|
||
clock.next(); | ||
clock.tick(150); | ||
clock.runAll(); | ||
const timeoutId = clock.setTimeout(() => {}); | ||
const intervalId = clock.setInterval(() => {}); | ||
clock.clearTimeout(timeoutId); | ||
|
||
// $ExpectError | ||
clock.clearTimeout(intervalId); | ||
clock.clearInterval(intervalId); | ||
clock.runToFrame(); | ||
}); | ||
}); |