Browse Source

chore: test add js dom

pull/5723/head
chenshuai2144 6 years ago
parent
commit
1449dca6ce
  1. 1
      jest.config.js
  2. 3
      package.json
  3. 22
      tests/setupTests.js

1
jest.config.js

@ -1,6 +1,7 @@
module.exports = { module.exports = {
testURL: 'http://localhost:8000', testURL: 'http://localhost:8000',
preset: 'jest-puppeteer', preset: 'jest-puppeteer',
extraSetupFiles: ['./tests/setupTests.js'],
globals: { globals: {
ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION: false, ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION: false,
localStorage: null, localStorage: null,

3
package.json

@ -83,7 +83,7 @@
"@types/classnames": "^2.2.7", "@types/classnames": "^2.2.7",
"@types/express": "^4.17.0", "@types/express": "^4.17.0",
"@types/history": "^4.7.2", "@types/history": "^4.7.2",
"@types/jest": "^24.0.13", "@types/jest": "^24.0.23",
"@types/lodash": "^4.14.144", "@types/lodash": "^4.14.144",
"@types/qs": "^6.5.3", "@types/qs": "^6.5.3",
"@types/react": "^16.8.19", "@types/react": "^16.8.19",
@ -103,6 +103,7 @@
"import-sort-parser-typescript": "^6.0.0", "import-sort-parser-typescript": "^6.0.0",
"import-sort-style-module": "^6.0.0", "import-sort-style-module": "^6.0.0",
"jest-puppeteer": "^4.2.0", "jest-puppeteer": "^4.2.0",
"jsdom-global": "^3.0.2",
"lint-staged": "^9.0.0", "lint-staged": "^9.0.0",
"mockjs": "^1.0.1-beta3", "mockjs": "^1.0.1-beta3",
"netlify-lambda": "^1.4.13", "netlify-lambda": "^1.4.13",

22
tests/setupTests.js

@ -0,0 +1,22 @@
import 'jsdom-global/register';
// browserMocks.js
const localStorageMock = (() => {
let store = {};
return {
getItem(key) {
return store[key] || null;
},
setItem(key, value) {
store[key] = value.toString();
},
clear() {
store = {};
},
};
})();
Object.defineProperty(window, 'localStorage', {
value: localStorageMock,
});
Loading…
Cancel
Save