-
-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
005cf7a
commit 7ad1d2a
Showing
2 changed files
with
33 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1 @@ | ||
const userAgent = typeof navigator !== 'undefined' ? navigator.userAgent : '' | ||
|
||
export default () => /(android)/i.test(userAgent) | ||
export default () => /(android)/i.test(typeof navigator !== 'undefined' ? navigator.userAgent : '') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}) | ||
}) |