test: fix a test

This commit is contained in:
Barış Soner Uşaklı
2025-05-05 10:57:43 -04:00
parent 800426d68b
commit 7ef79981dd
2 changed files with 13 additions and 7 deletions

View File

@@ -507,9 +507,15 @@ const utils = {
return str.toString().replace(escapeChars, replaceChar);
},
isAndroidBrowser: function () {
isAndroidBrowser: function (nua) {
if (!nua) {
if (typeof navigator !== 'undefined' && navigator.userAgent) {
nua = navigator.userAgent;
} else {
return false;
}
}
// http://stackoverflow.com/questions/9286355/how-to-detect-only-the-native-android-browser
const nua = navigator.userAgent;
return ((nua.indexOf('Mozilla/5.0') > -1 && nua.indexOf('Android ') > -1 && nua.indexOf('AppleWebKit') > -1) && !(nua.indexOf('Chrome') > -1));
},

View File

@@ -285,18 +285,18 @@ describe('Utility Methods', () => {
});
it('should return false if browser is not android', (done) => {
global.navigator = {
const navigator = {
userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.96 Safari/537.36',
};
assert.equal(utils.isAndroidBrowser(), false);
assert.equal(utils.isAndroidBrowser(navigator.userAgent), false);
done();
});
it('should return true if browser is android', (done) => {
global.navigator = {
userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Android /58.0.3029.96 Safari/537.36',
const navigator = {
userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.96 Safari/537.36',
};
assert.equal(utils.isAndroidBrowser(), true);
assert.equal(utils.isAndroidBrowser(navigator.userAgent), true);
done();
});