Created
February 22, 2017 19:21
-
-
Save ronaiza-cardoso/116bfdf47820fd0534050c56fb343f0c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
(function () { | |
angular | |
.module('myinfo.isMobile', []) | |
.service('isMobile', isMobile); | |
function isMobile () { | |
const isMobile = { | |
Android: () => { | |
return navigator.userAgent.match(/Android/i) && navigator.userAgent.match(/wv/i); | |
}, | |
iOS: () => { | |
return navigator.userAgent.match(/iPhone|iPad|iPod/i); | |
}, | |
any: () => { | |
return (isMobile.Android() || isMobile.iOS()); | |
} | |
}; | |
return isMobile; | |
} | |
}()); |
This file contains hidden or 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
'use strict'; | |
describe('isMobile module', () => { | |
let isMobile; | |
beforeEach(module('myinfo.isMobile')); | |
beforeEach(() => { | |
const userAgent = 'Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1'; | |
module('myinfo.isMobile', $provide => { | |
$provide.value('navigator', userAgent); | |
}); | |
}); | |
beforeEach(inject((_isMobile_) => { | |
isMobile = _isMobile_; | |
})); | |
describe('isMobile module testing', () => { | |
it('isMobile.any should be defined', () => { | |
expect(isMobile.any()).toBeDefined(); | |
}); | |
it('isMobile.Android should be defined', () => { | |
expect(isMobile.Android()).toBeDefined(); | |
}); | |
it('isMobile.iOS should be defined', () => { | |
expect(isMobile.iOS()).toBeDefined(); | |
}); | |
it('isMobile.iOS should be true', () => { | |
expect(isMobile.iOS()).toEqual(true); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment