-
Notifications
You must be signed in to change notification settings - Fork 40
/
index.ts
93 lines (82 loc) · 1.97 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import {
getTestScheduler,
initTestScheduler,
resetTestScheduler,
} from './src/scheduler';
import {
TestColdObservable,
TestHotObservable,
TestObservable,
} from './src/test-observables';
import {
toHaveSubscriptionsComparer,
toBeObservableComparer,
} from './src/utils';
export {
getTestScheduler,
initTestScheduler,
resetTestScheduler,
} from './src/scheduler';
export function hot(
marbles: string,
values?: any,
error?: any,
): TestHotObservable {
return new TestHotObservable(marbles.trim(), values, error);
}
export function cold(
marbles: string,
values?: any,
error?: any,
): TestColdObservable {
return new TestColdObservable(marbles.trim(), values, error);
}
export function time(marbles: string): number {
return getTestScheduler().createTime(marbles.trim());
}
declare global {
namespace jasmine {
interface Matchers<T> {
toBeObservable(expected: TestObservable): boolean;
toHaveSubscriptions(marbles: string | string[]): boolean;
}
}
namespace jest {
interface Matchers<R> {
toBeObservable(expected: TestObservable): R;
toHaveSubscriptions(marbles: string | string[]): R;
}
}
}
export function addMatchers() {
/**
* expect.extend is an API exposed by jest-circus,
* the default runner as of Jest v27. If that method
* is not available, assume we're in a Jasmine test
* environment.
*/
if (!expect.extend) {
jasmine.addMatchers({
toHaveSubscriptions: () => ({
compare: toHaveSubscriptionsComparer,
}),
toBeObservable: (_utils) => ({
compare: toBeObservableComparer,
}),
});
} else {
expect.extend({
toHaveSubscriptions: toHaveSubscriptionsComparer,
toBeObservable: toBeObservableComparer,
});
}
}
export function setupEnvironment() {
beforeAll(() => addMatchers());
beforeEach(() => initTestScheduler());
afterEach(() => {
getTestScheduler().flush();
resetTestScheduler();
});
}
setupEnvironment();