Skip to content

Commit 2ec4ed9

Browse files
xiaokesongxiejay97
authored andcommitted
test(ui): add tmp test of button
1 parent 6565d0f commit 2ec4ed9

File tree

5 files changed

+172
-872
lines changed

5 files changed

+172
-872
lines changed

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"@types/fs-extra": "^9.0.13",
4848
"@types/glob": "^8.0.0",
4949
"@types/inquirer": "^8.2.5",
50-
"@types/jest": "^27.4.1",
50+
"@types/jest": "28.1.1",
5151
"@types/lodash": "^4.14.191",
5252
"@types/marked": "^4.0.8",
5353
"@types/node": "16.18.0",
@@ -59,7 +59,7 @@
5959
"@typescript-eslint/parser": "^5.46.1",
6060
"axios": "^1.2.1",
6161
"axios-mock-adapter": "^1.21.2",
62-
"babel-jest": "^29.1.2",
62+
"babel-jest": "28.1.1",
6363
"bootstrap": "^5.2.3",
6464
"codesandbox": "^2.2.3",
6565
"colors": "^1.4.0",
@@ -84,7 +84,7 @@
8484
"immer": "^9.0.16",
8585
"inquirer": "^8.2.5",
8686
"is-builtin-module": "^3.2.0",
87-
"jest": "^27.5.1",
87+
"jest": "28.1.1",
8888
"jest-environment-jsdom": "28.1.1",
8989
"jsurl": "^0.1.5",
9090
"lerna": "^6.1.0",
@@ -112,7 +112,7 @@
112112
"stylelint-config-standard": "^29.0.0",
113113
"stylelint-scss": "^4.3.0",
114114
"table": "^6.8.1",
115-
"ts-jest": "^27.1.4",
115+
"ts-jest": "28.0.5",
116116
"ts-node": "^10.9.1",
117117
"tslib": "^2.4.1",
118118
"typescript": "~4.9.4",

packages/ui/jest.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ module.exports = {
2020
displayName: 'ui',
2121
preset: '../../jest.preset.js',
2222
transform: {
23-
'^.+\\.[tj]sx?$': 'babel-jest',
23+
'^(?!.*\\.(js|jsx|ts|tsx|css|json)$)': '@nrwl/react/plugins/jest',
24+
'^.+\\.[tj]sx?$': ['babel-jest', { presets: ['@nrwl/react/babel'] }],
2425
},
2526
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
2627
collectCoverage: true,

packages/ui/src/__tests__/utils.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { render } from '@testing-library/react';
2+
import React from 'react';
3+
4+
import { DRoot } from '../components/root';
5+
6+
const AllTheProviders: React.JSXElementConstructor<{ children: React.ReactElement }> = ({ children }) => {
7+
return React.createElement(DRoot, undefined, children);
8+
};
9+
10+
const customRender = ((ui: any, options: any) => render(ui, { wrapper: AllTheProviders, ...options })) as typeof render;
11+
12+
// re-export everything
13+
export * from '@testing-library/react';
14+
15+
// override render method
16+
export { customRender as render };
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { render } from '../../__tests__/utils';
2+
import { DButton } from './index';
3+
4+
describe('DButton', () => {
5+
const text = 'This is DButton';
6+
7+
it('should `children` work', () => {
8+
const { getByText } = render(<DButton children={text} />);
9+
expect(getByText(text)).toBeInTheDocument();
10+
});
11+
});

0 commit comments

Comments
 (0)