-
Notifications
You must be signed in to change notification settings - Fork 21
/
jest.ts
49 lines (45 loc) · 1.62 KB
/
jest.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
export interface SnapshotState {
_counters: Map<string, number>;
_updateSnapshot: "new" | "all" | "none";
updated: number;
added: number;
}
export interface JestTestConfiguration {
snapshotState: SnapshotState;
testPath: string;
currentTestName: string;
isNot: boolean;
}
export interface MatcherResult {
message?(): string;
pass: boolean;
actual?: string;
expected?: string;
}
/**
* Checks whether the given input is a `SnapshotState` provided by jest.
*/
export function isSnapshotState(obj: any): obj is SnapshotState {
if (typeof obj !== "object") { return false; }
if (obj === null) { return false; }
const { _counters, _updateSnapshot, updated, added } = obj;
if (!(_counters instanceof Map)) { return false; }
const isUpdateSnapshot = _updateSnapshot === "new" || _updateSnapshot === "none" || _updateSnapshot === "all";
if (!isUpdateSnapshot) { return false; }
if (typeof updated !== "number") { return false; }
if (typeof added !== "number") { return false; }
return true;
}
/**
* Checks whether the given input is a `JestTestConfiguration` provided by jest.
*/
export function isJestTestConfiguration(obj: any): obj is JestTestConfiguration {
if (typeof obj !== "object") { return false; }
if (obj === null) { return false; }
const { snapshotState, testPath, currentTestName, isNot } = obj;
if (typeof testPath !== "string") { return false; }
if (typeof currentTestName !== "string") { return false; }
if (typeof isNot !== "boolean") { return false; }
if (!isSnapshotState(snapshotState)) { return false; }
return true;
}