Skip to content

Commit c62d560

Browse files
committed
add test case
1 parent 59322ff commit c62d560

9 files changed

Lines changed: 7080 additions & 1272 deletions

File tree

__mocks__/fileMock.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// __mocks__/fileMock.js
2+
export default 'test-file-stub';

__mocks__/styleMock.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// __mocks__/styleMock.js
2+
export default {};

__tests__/App.spec.jsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import React from 'react';
2+
import { render, screen } from '@testing-library/react';
3+
import '@testing-library/jest-dom';
4+
import App from '../src/App';
5+
6+
describe('App', () => {
7+
it('renders the app heading and welcome message', () => {
8+
render(<App />);
9+
10+
const heading = screen.getByRole('heading', { name: /docker \+ react/i });
11+
const message = screen.getByText(/hello from docker react project/i);
12+
13+
expect(heading).toBeInTheDocument();
14+
expect(message).toBeInTheDocument();
15+
});
16+
});

babel.config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// babel.config.js
2+
export default {
3+
presets: ['@babel/preset-env', '@babel/preset-react'],
4+
};

eslint.config.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import js from '@eslint/js'
2-
import globals from 'globals'
3-
import reactHooks from 'eslint-plugin-react-hooks'
4-
import reactRefresh from 'eslint-plugin-react-refresh'
1+
import js from '@eslint/js';
2+
import globals from 'globals';
3+
import reactHooks from 'eslint-plugin-react-hooks';
4+
import reactRefresh from 'eslint-plugin-react-refresh';
55

66
export default [
77
{ ignores: ['dist'] },
@@ -30,4 +30,16 @@ export default [
3030
],
3131
},
3232
},
33-
]
33+
{
34+
files: [
35+
'**/*.test.{js,jsx}',
36+
'**/*.spec.{js,jsx}',
37+
'**/__tests__/**/*.{js,jsx}',
38+
],
39+
languageOptions: {
40+
globals: {
41+
...globals.jest,
42+
},
43+
},
44+
},
45+
];

jest.config.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// jest.config.js
2+
export default {
3+
testEnvironment: 'jsdom',
4+
transform: {
5+
'^.+\\.[jt]sx?$': 'babel-jest',
6+
},
7+
moduleFileExtensions: ['js', 'jsx'],
8+
// setupFilesAfterEnv: ['@testing-library/jest-dom'],
9+
setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
10+
11+
moduleNameMapper: {
12+
'\\.(css|less|scss|sass)$': '<rootDir>/__mocks__/styleMock.js',
13+
'\\.(jpg|jpeg|png|gif|svg)$': '<rootDir>/__mocks__/fileMock.js',
14+
},
15+
};

jest.setup.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import '@testing-library/jest-dom';

0 commit comments

Comments
 (0)