-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Mocker.ts
54 lines (51 loc) · 1.15 KB
/
Mocker.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
function getRandomInt(max: number) {
return Math.floor(Math.random() * Math.floor(max));
}
const testSymbol = Symbol("test");
export class Mocker {
pick = (...args: any[]) => {
return args[getRandomInt(args.length)];
};
get string() {
return Math.random().toString(36).substring(7);
}
get number() {
return Math.random() * 100;
}
get bigint() {
return BigInt(Math.floor(Math.random() * 10000));
}
get boolean() {
return Math.random() < 0.5;
}
get date() {
return new Date(Math.floor(Date.now() * Math.random()));
}
get symbol() {
return testSymbol;
}
get null(): null {
return null;
}
get undefined(): undefined {
return undefined;
}
get stringOptional() {
return this.pick(this.string, this.undefined);
}
get stringNullable() {
return this.pick(this.string, this.null);
}
get numberOptional() {
return this.pick(this.number, this.undefined);
}
get numberNullable() {
return this.pick(this.number, this.null);
}
get booleanOptional() {
return this.pick(this.boolean, this.undefined);
}
get booleanNullable() {
return this.pick(this.boolean, this.null);
}
}