-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-env-setup.ts
70 lines (63 loc) · 1.42 KB
/
test-env-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
61
62
63
64
65
66
67
68
69
70
const speechRecognitionPrototype = {
grammars: undefined,
lang: 'en',
continuous: false,
interimResults: false,
maxAlternatives: 0,
serviceURI: '',
start: jest.fn(),
stop: jest.fn(),
abort: jest.fn(),
onaudiostart: jest.fn(),
onsoundstart: jest.fn(),
onspeechstart: jest.fn(),
onspeechend: jest.fn(),
onsoundend: jest.fn(),
onaudioend: jest.fn(),
onresult: jest.fn(),
onnomatch: jest.fn(),
onerror: jest.fn(),
onstart: jest.fn(),
onend: jest.fn(),
}
const speechGrammarListPrototype = {
addFromString: jest.fn(),
}
const speechUtterancePrototype = {
lang: 'en',
voice: undefined,
text: '',
onerror: jest.fn(),
onstart: jest.fn(),
onend: jest.fn(),
}
export const SpeechRecognitionMock = Object.defineProperty(
window,
'SpeechRecognition',
{
writable: true,
value: jest.fn().mockImplementation(() => ({
prototype: speechRecognitionPrototype,
new: () => speechRecognitionPrototype,
})),
}
)
export const SpeechGrammarListMock = Object.defineProperty(
window,
'SpeechGrammarList',
{
writable: true,
value: jest.fn().mockImplementation(() => ( speechGrammarListPrototype)),
}
)
export const SpeechUtteranceMock = Object.defineProperty(
window,
'SpeechSynthesisUtterance',
{
writable: true,
value: jest.fn().mockImplementation(() => ({
prototype: speechUtterancePrototype,
new: () => speechUtterancePrototype,
})),
}
)