-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
jest.setup.ts
60 lines (52 loc) · 1.33 KB
/
jest.setup.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
declare global {
namespace jest {
interface Matchers<R, T> {
toHaveBeenWarned(): R
toHaveBeenWarnedLast(): R
toHaveBeenWarnedTimes(n: number): R
}
}
}
import { getCurrentPlatform } from '@nativescript-vue/test-utils'
const coreMocks = new Map<string, any>()
export const registerCoreMock = (name: string, mock: any) => {
coreMocks.set(name, mock)
}
export const unsetValue = Symbol('unsetValue')
jest.mock(
'@nativescript/core',
() =>
new Proxy(
{},
{
get(target, p) {
// todo: refactor to be able to use registerCoreMock for everything
// by checking the type and if it's a factory function, call it
switch (p) {
case 'isAndroid':
return getCurrentPlatform() === 'Android'
case 'isIOS':
return getCurrentPlatform() === 'iOS'
default:
if (coreMocks.has(p as string)) {
return coreMocks.get(p as string)
}
throw new Error(
`Requested mock has not been specified ${p.toString()}`
)
}
},
}
),
{ virtual: true }
)
registerCoreMock('unsetValue', unsetValue)
registerCoreMock('Trace', {
write() {},
categories: {
Debug: 'debug',
},
messageType: {
log: 'log',
},
})