-
Notifications
You must be signed in to change notification settings - Fork 0
/
isMacroabled.test.ts
72 lines (57 loc) · 2.39 KB
/
isMacroabled.test.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
import { macro, mixin } from '../../src';
import isMacroabled from '../../src/is/isMacroabled';
import isMacroedWith from '../../src/is/isMacroedWith';
import macroable from '../../src/macroable';
describe('is:isMacroabled', () => {
it('works', () => {
class Yolo {
hey = 'hey';
ooh(): string {
return 'ooh';
}
get length(): number {
return 7;
}
}
expect(isMacroabled(Yolo)).toEqual(false);
expect(isMacroabled(Yolo.prototype)).toEqual(false);
// @ts-expect-error shush
Yolo.prototype.__macros__ = new Set();
// @ts-expect-error shush
Yolo.__macros__ = new Set();
expect(isMacroabled(Yolo)).toEqual(false);
expect(isMacroabled(Yolo.prototype)).toEqual(false);
// @ts-expect-error shush
Yolo.prototype.__macros__.add('hasMacro');
// @ts-expect-error shush
Yolo.__macros__.add('hasMacro');
expect(isMacroabled(Yolo)).toEqual(false);
expect(isMacroabled(Yolo.prototype)).toEqual(false);
// @ts-expect-error shush
Yolo.prototype.__macros__.add('macro');
// @ts-expect-error shush
Yolo.__macros__.add('macro');
expect(isMacroabled(Yolo)).toEqual(false);
expect(isMacroabled(Yolo.prototype)).toEqual(false);
// @ts-expect-error shush
Yolo.prototype.__macros__.add('mixin');
// @ts-expect-error shush
Yolo.__macros__.add('mixin');
expect(isMacroabled(Yolo)).toEqual(false);
expect(isMacroabled(Yolo.prototype)).toEqual(false);
// @ts-expect-error shush
Yolo.prototype.__macros__.clear();
// @ts-expect-error shush
Yolo.__macros__.clear();
expect(isMacroabled(Yolo)).toEqual(false);
expect(isMacroabled(Yolo.prototype)).toEqual(false);
macroable(Yolo);
macroable(Yolo, null, { onFunctionPrototype: false });
expect(isMacroabled(Yolo)).toEqual(true);
expect(isMacroabled(Yolo.prototype)).toEqual(true);
// eslint-disable-next-line @typescript-eslint/no-empty-function
expect(isMacroabled({ hasMacro() {}, macro() {}, mixin() {} })).toEqual(false);
expect(isMacroabled({ hasMacro: isMacroedWith, macro: macro, mixin: mixin })).toEqual(false);
expect(isMacroabled(macroable({}))).toEqual(true);
});
});