Skip to content

Commit

Permalink
Merge pull request #62 from JamesBrill/ssr-support
Browse files Browse the repository at this point in the history
Fix SSR support
  • Loading branch information
JamesBrill authored Aug 26, 2020
2 parents 407fa47 + 7ad1d2a commit 5fa4761
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-speech-recognition",
"version": "3.2.1",
"version": "3.2.2",
"description": "💬Speech recognition for your React app",
"main": "lib/index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion src/isAndroid.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export default () => /(android)/i.test(typeof navigator !== 'undefined' ? navigator.userAgent : "")
export default () => /(android)/i.test(typeof navigator !== 'undefined' ? navigator.userAgent : '')
32 changes: 32 additions & 0 deletions src/isAndroid.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import isAndroid from './isAndroid'

const mockUserAgent = (userAgent) => {
Object.defineProperty(navigator, 'userAgent', { value: userAgent, writable: true })
}

const mockUndefinedNavigator = () => {
Object.defineProperty(global, 'navigator', { value: undefined, writable: true })
}

describe('isAndroid', () => {
test('returns false when navigator.userAgent does not contain android string', () => {
mockUserAgent('safari browser')
const result = isAndroid()

expect(result).toEqual(false)
})

test('returns true when navigator.userAgent contains android string', () => {
mockUserAgent('android browser')
const result = isAndroid()

expect(result).toEqual(true)
})

test('returns false when navigator is undefined', () => {
mockUndefinedNavigator()
const result = isAndroid()

expect(result).toEqual(false)
})
})

0 comments on commit 5fa4761

Please sign in to comment.