Skip to content

Commit dcace32

Browse files
committed
Add types to kefit-test-utils
1 parent 19ffb07 commit dcace32

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

kefir-test-utils.d.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import {Observable, Stream, Property, Event as KEvent, Pool} from 'kefir'
2+
import {Clock} from 'lolex'
3+
4+
export type Event<V, E> = KEvent<V, E> & {
5+
current?: boolean
6+
}
7+
8+
export type Options = {current: boolean}
9+
10+
export type Watcher<V, E> = {
11+
log: Event<V, E>[]
12+
unwatch(): void
13+
}
14+
15+
export interface Helpers {
16+
END: string
17+
VALUE: string
18+
ERROR: string
19+
send<V, E>(stream$: Observable<V, E>, values: Event<V, E>[]): Observable<V, E>
20+
value<V, E>(v: V, opts?: Options): Event<V, E>
21+
error<V, E>(e: E, opts?: Options): Event<V, E>
22+
end<V, E>(opts?: Options): Event<V, E>
23+
activate<V, E>(obs: Observable<V, E>): typeof obs
24+
deactivate<V, E>(obs: Observable<V, E>): typeof obs
25+
prop<V, E>(): Property<V, E>
26+
stream<V, E>(): Stream<V, E>
27+
pool<V, E>(): Pool<V, E>
28+
shakeTimers(clock: Clock): void
29+
withFakeTime(cb: (tick: (x: number) => void, clock: Clock) => void, reverseSimultaneous?: boolean): void
30+
logItem<V, E>(event: KEvent<V, E>, current: boolean): Event<V, E>
31+
watch<V, E>(obs: Observable<V, E>): Watcher<V, E>
32+
watchWithTime<V, E>(stream$: Observable<V, E>): Event<V, E>[]
33+
}
34+
35+
export interface HelpersFactory {
36+
(Kefir: typeof import('kefir').default): Helpers
37+
}
38+
39+
declare const createHelpers: HelpersFactory
40+
41+
export default createHelpers

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
"version": "1.0.0",
44
"description": "Framework-agnostic testing tools for Kefir",
55
"main": "dist/index.js",
6+
"types": "kefir-test-utils.d.ts",
67
"scripts": {
78
"build": "babel src -d dist",
89
"prepublishOnly": "npm test && npm run build",
10+
"fmt": "prettier src/*.js test/*.js kefir-test-utils.d.ts --write",
911
"test": "npm run build && npm run test:fmt && npm run test:unit",
1012
"test:unit": "nyc mocha",
11-
"test:fmt": "prettier src/*.js test/*.js --write"
13+
"test:fmt": "prettier src/*.js test/*.js kefir-test-utils.d.ts --check"
1214
},
1315
"files": [
1416
"dist",

0 commit comments

Comments
 (0)