Add unit testing
This commit is contained in:
parent
ff88e2f322
commit
a198e56471
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
"presets": [[
|
||||
"@babel/preset-env",
|
||||
{
|
||||
"corejs": "3",
|
||||
"useBuiltIns": "usage"
|
||||
}
|
||||
]],
|
||||
"plugins": [
|
||||
"@babel/plugin-transform-runtime",
|
||||
"@babel/plugin-proposal-class-properties"
|
||||
]
|
||||
}
|
|
@ -28,4 +28,10 @@ module.exports = {
|
|||
'vue/no-unused-vars': 0,
|
||||
'vue/html-self-closing': 0,
|
||||
},
|
||||
'globals': {
|
||||
'describe': true,
|
||||
'expect': true,
|
||||
'it': true,
|
||||
'test': true,
|
||||
},
|
||||
};
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -25,6 +25,9 @@
|
|||
"test:sass-lint": "sass-lint 'src/**/*.scss' --verbose --no-exit --config .sasslintrc",
|
||||
"test:sass-lint:fix": "sass-lint-auto-fix 'src/**/*.scss'"
|
||||
},
|
||||
"jest": {
|
||||
"testRegex": "/test/.*.js?$"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/digitalocean/nginxconfig.io.git"
|
||||
|
@ -57,12 +60,18 @@
|
|||
"vue-select": "^3.10.8"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/plugin-proposal-class-properties": "^7.10.4",
|
||||
"@babel/plugin-transform-runtime": "^7.11.5",
|
||||
"@babel/preset-env": "^7.11.5",
|
||||
"@babel/runtime": "^7.11.2",
|
||||
"@vue/cli-service": "^4.5.7",
|
||||
"babel-eslint": "^10.1.0",
|
||||
"copyfiles": "^2.4.0",
|
||||
"core-js": "^3.6.5",
|
||||
"duplicate-package-checker-webpack-plugin": "^3.0.0",
|
||||
"eslint": "^7.11.0",
|
||||
"eslint-plugin-vue": "^7.0.1",
|
||||
"jest": "^26.6.3",
|
||||
"sass": "^1.27.0",
|
||||
"sass-lint": "^1.13.1",
|
||||
"sass-lint-auto-fix": "^0.21.2",
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
import browserLanguage from '../src/nginxconfig/util/browser_language';
|
||||
|
||||
let languages = [];
|
||||
|
||||
Object.defineProperty(window.navigator,'languages',{get:function(){
|
||||
return languages;
|
||||
}});
|
||||
|
||||
Object.defineProperty(window.navigator,'language',{get:function(){
|
||||
return languages[0];
|
||||
}});
|
||||
|
||||
const setNavigatorLanguges = lang => { languages = lang; };
|
||||
|
||||
// eslint-disable-next-line no-global-assign
|
||||
Intl = undefined;
|
||||
|
||||
describe('#testGetBrowserLanguage', function() {
|
||||
test('#inChina', function() {
|
||||
setNavigatorLanguges(['zh-CN', 'zh', 'en-US', 'en']);
|
||||
expect(browserLanguage()).toEqual('zhCN');
|
||||
});
|
||||
|
||||
test('#inHongKong',function (){
|
||||
setNavigatorLanguges(['zh-TW','zh','en-US','en']);
|
||||
expect(browserLanguage()).toEqual('zhTW');
|
||||
});
|
||||
|
||||
test('#inJapan',function(){
|
||||
setNavigatorLanguges(['ja-JP','ja']);
|
||||
expect(browserLanguage()).toBeFalsy();
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue