Skip to content

Node.js based forum software built for the modern web

test: fix a test

Barış Soner Uşaklı7ef79981ddfd
diff --git a/public/src/utils.common.js b/public/src/utils.common.js
index 66785a6467..0014b3ae85 100644
--- a/public/src/utils.common.js
+++ b/public/src/utils.common.js
@@ -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));
},
diff --git a/test/utils.js b/test/utils.js
index 68371c1afd..0af0de8bf6 100644
--- a/test/utils.js
+++ b/test/utils.js
@@ -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();
});