Skip to content

Commit

Permalink
Merge pull request crabbly#257 from tvdeyen/fix-chrome-detection
Browse files Browse the repository at this point in the history
Fix chrome detection
  • Loading branch information
crabbly authored Nov 21, 2018
2 parents a50a41d + 269efa6 commit d88b8e4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/js/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ const Browser = {
return !Browser.isIE() && !!window.StyleMedia
},
// Chrome 1+
isChrome: () => {
return !!window.chrome && !!window.chrome.webstore
isChrome: (context = window) => {
return !!context.chrome
},
// At least Safari 3+: "[object HTMLElementConstructor]"
isSafari: () => {
Expand Down
12 changes: 12 additions & 0 deletions test/unit/browser.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@ describe('Browser', () => {
expect(typeof Browser.isChrome()).toBe('boolean')
})

describe('isChrome()', () => {
it('returns true for Google Chrome', () => {
const stubbedWindow = { chrome: {} }
expect(Browser.isChrome(stubbedWindow)).toBeTruthy()
})

it('returns false for non Google Chrome', () => {
const stubbedWindow = {}
expect(Browser.isChrome(stubbedWindow)).toBeFalsy()
})
})

it('has a function named isSafari that returns a boolean value', () => {
expect(typeof Browser.isSafari).toBe('function')
expect(typeof Browser.isSafari()).toBe('boolean')
Expand Down

0 comments on commit d88b8e4

Please sign in to comment.