Skip to content

add jest #101

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions admin-ui/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'jsdom',
moduleNameMapper: {
'\\.(css|less|scss|sass)$': 'identity-obj-proxy',
},
setupFilesAfterEnv: ['<rootDir>/jest.setup.ts'],
};
41 changes: 0 additions & 41 deletions admin-ui/jest.config.ts

This file was deleted.

15 changes: 15 additions & 0 deletions admin-ui/jest.setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import '@testing-library/jest-dom';

Object.defineProperty(window, 'matchMedia', {
writable: true,
value: jest.fn().mockImplementation(query => ({
matches: false,
media: query,
onchange: null,
addListener: jest.fn(), // 旧版 API
removeListener: jest.fn(), // 旧版 API
addEventListener: jest.fn(), // 新版 API
removeEventListener: jest.fn(), // 新版 API
dispatchEvent: jest.fn(),
})),
});
13 changes: 13 additions & 0 deletions admin-ui/jest/map.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import '@testing-library/jest-dom';


test("map", () => {
const map = new Map();
map.set('key', 'value');
expect(map.get('key')).toBe('value');
expect(map.has('key')).toBe(true);
expect(map.size).toBe(1);
map.delete('key');
expect(map.has('key')).toBe(false);
expect(map.size).toBe(0);
})
4 changes: 2 additions & 2 deletions admin-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"@babel/preset-typescript": "^7.26.0",
"@testing-library/dom": "^10.4.0",
"@testing-library/jest-dom": "^6.6.3",
"@testing-library/react": "^16.1.0",
"@testing-library/react": "^16.3.0",
"@types/jest": "^29.5.14",
"@types/lodash": "^4.17.7",
"@types/lodash-es": "^4.17.12",
Expand All @@ -85,7 +85,7 @@
"sass": "^1.78.0",
"sass-loader": "^16.0.1",
"style-loader": "^4.0.0",
"ts-jest": "^29.2.5",
"ts-jest": "^29.3.2",
"ts-loader": "^9.5.1",
"ts-node": "^10.9.2",
"webpack": "^5.94.0",
Expand Down
8 changes: 8 additions & 0 deletions mobile-ui/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'jsdom',
moduleNameMapper: {
'\\.(css|less|scss|sass)$': 'identity-obj-proxy',
},
setupFilesAfterEnv: ['<rootDir>/jest.setup.ts'],
};
15 changes: 15 additions & 0 deletions mobile-ui/jest.setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import '@testing-library/jest-dom';

Object.defineProperty(window, 'matchMedia', {
writable: true,
value: jest.fn().mockImplementation(query => ({
matches: false,
media: query,
onchange: null,
addListener: jest.fn(), // 旧版 API
removeListener: jest.fn(), // 旧版 API
addEventListener: jest.fn(), // 新版 API
removeEventListener: jest.fn(), // 新版 API
dispatchEvent: jest.fn(),
})),
});
13 changes: 13 additions & 0 deletions mobile-ui/jest/map.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import '@testing-library/jest-dom';


test("map", () => {
const map = new Map();
map.set('key', 'value');
expect(map.get('key')).toBe('value');
expect(map.has('key')).toBe(true);
expect(map.size).toBe(1);
map.delete('key');
expect(map.has('key')).toBe(false);
expect(map.size).toBe(0);
})
15 changes: 13 additions & 2 deletions mobile-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@
"scripts": {
"start": "webpack serve --config webpack.config.mock.js --open",
"dev": "webpack serve --config webpack.config.dev.js --open",
"build": "webpack --mode production --config webpack.config.prod.js"
"build": "webpack --mode production --config webpack.config.prod.js",
"test": "jest",
"test:watch": "jest --watchAll"
},
"eslintConfig": {
"extends": [
Expand All @@ -59,16 +61,25 @@
"@types/lodash": "^4.17.7",
"@types/lodash-es": "^4.17.12",
"@types/react-resizable": "^3.0.8",
"@testing-library/dom": "^10.4.0",
"@testing-library/jest-dom": "^6.6.3",
"@testing-library/react": "^16.3.0",
"@types/jest": "^29.5.14",
"@types/mockjs": "^1.0.10",
"babel-jest": "^29.7.0",
"clean-webpack-plugin": "^4.0.0",
"copy-webpack-plugin": "^12.0.2",
"css-loader": "^7.1.2",
"express": "^4.21.0",
"html-webpack-plugin": "^5.6.0",
"identity-obj-proxy": "^3.0.0",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"mockjs": "^1.1.0",
"monaco-editor-webpack-plugin": "^7.1.0",
"sass": "^1.78.0",
"sass-loader": "^16.0.1",
"style-loader": "^4.0.0",
"ts-jest": "^29.3.2",
"ts-loader": "^9.5.1",
"webpack": "^5.94.0",
"webpack-cli": "^5.1.4",
Expand Down
2 changes: 0 additions & 2 deletions mobile-ui/webpack.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const {CleanWebpackPlugin} = require('clean-webpack-plugin');
const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin');
const ModuleFederationPlugin = require("webpack/lib/container/ModuleFederationPlugin");
const {dependencies} = require("./package.json");

Expand Down Expand Up @@ -56,7 +55,6 @@ module.exports = {
},
plugins: [
new CleanWebpackPlugin(),
new MonacoWebpackPlugin(),
new HtmlWebpackPlugin({
template: './public/index.html',
}),
Expand Down