Skip to content

Commit

Permalink
fix: Fix grammars default value to null
Browse files Browse the repository at this point in the history
  • Loading branch information
Vincent Le Badezet committed Jul 15, 2020
1 parent 4079ce7 commit d27db45
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/SpeechRecognitionWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ class SpeechRecognitionWrapper {
this._instance = new SpeechRecognition()
this._listeners = {}

if(!!options && !options.grammars) {
const SpeechGrammarList =
window.SpeechGrammarList ||
window.webkitSpeechGrammarList ||
window.mozSpeechGrammarList ||
window.msSpeechGrammarList ||
{}
this._instance.grammars = new SpeechGrammarList()
}

Object.entries({ ...SpeechRecognitionWrapper.defaultOptions, ...(options || {}) }).forEach(
([key, value]) => (this._instance[key] = value)
)
Expand Down
4 changes: 4 additions & 0 deletions src/__tests__/Vocal.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ describe('Vocal', () => {
getUserMedia: jest.fn().mockResolvedValue('foo'),
}))
global.navigator.mediaDevices = new MediaDevices()
global.SpeechGrammarList = jest.fn(() => ({
length: 0,
}))
global.SpeechRecognition = jest.fn(() => {
const handlers = {}
return {
Expand Down Expand Up @@ -71,6 +74,7 @@ describe('Vocal', () => {
global.PermissionStatus.mockReset()
global.Permissions.mockReset()
global.MediaDevices.mockReset()
global.SpeechGrammarList.mockReset()
global.SpeechRecognition.mockReset()
})

Expand Down

0 comments on commit d27db45

Please sign in to comment.