Skip to content

Commit 4d720ea

Browse files
authored
Merge pull request #13 from kefirjs/add-typings
Add types to kefir-test-utils
2 parents 19ffb07 + bf032ef commit 4d720ea

File tree

6 files changed

+1809
-170
lines changed

6 files changed

+1809
-170
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ node_js:
66
- 6
77
- 8
88
- 10
9+
- 12

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

kefir-test-utils.test-d.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import {expectType} from 'tsd'
2+
import Kefir from 'kefir'
3+
import {Clock} from 'lolex'
4+
import createHelpers, {Event, Watcher} from '.'
5+
6+
const {VALUE, ERROR, END, value, error, end, withFakeTime, logItem, watch, watchWithTime} = createHelpers(Kefir)
7+
8+
expectType<string>(VALUE)
9+
expectType<string>(ERROR)
10+
expectType<string>(END)
11+
12+
expectType<Event<string, any>>(value('hello'))
13+
expectType<Event<any, string>>(error('hello'))
14+
expectType<Event<any, any>>(end())
15+
16+
expectType<void>(
17+
withFakeTime((tick: (s: number) => void, clock: Clock) => {
18+
tick(10)
19+
clock.runToLast()
20+
})
21+
)
22+
expectType<Event<string, number>>(logItem({type: 'value', value: 'hello'}, false))
23+
expectType<Watcher<string, number>>(watch(new Kefir.Stream<string, number>()))
24+
expectType<Event<string, number>[]>(watchWithTime(new Kefir.Stream<string, number>()))

0 commit comments

Comments
 (0)