Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fjsj committed Nov 28, 2023
1 parent 8ccb015 commit 28cd256
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 15,521 deletions.
4 changes: 3 additions & 1 deletion babel.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
"corejs": "3.22"
}
],
"@babel/preset-react"
["@babel/preset-react", {
"runtime": "automatic"
}]
]
}
40 changes: 40 additions & 0 deletions frontend/js/pages/__tests__/Home.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { render, screen, waitFor } from '@testing-library/react';
import { useDispatch, useSelector } from 'react-redux';
import { fetchRestCheck } from '../../store/rest_check';
import Home from '../Home';

jest.mock('react-redux', () => ({
useDispatch: jest.fn(),
useSelector: jest.fn(),
}));

jest.mock('../../store/rest_check', () => ({
fetchRestCheck: jest.fn(),
}));

describe('Home', () => {
beforeEach(() => {
useDispatch.mockReturnValue(jest.fn());
useSelector.mockReturnValue({ data: { payload: { result: 'Test Result' } } });
});

afterEach(() => {
jest.clearAllMocks();
});

test('renders static assets and rest API data', async () => {
render(<Home />);

expect(screen.getByText('Static assets')).toBeInTheDocument();
expect(screen.getByText('Rest API')).toBeInTheDocument();
expect(screen.getByText('Test Result')).toBeInTheDocument();
});

test('dispatches fetchRestCheck action on mount', async () => {
render(<Home />);

await waitFor(() => {
expect(fetchRestCheck).toHaveBeenCalled();
});
});
});
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = {
'^.+\\.js$': 'babel-jest',
},
moduleNameMapper: {
'^.+\\.(css|scss)$': 'identity-obj-proxy',
'^.+\\.(css|scss|png|svg|jpg|jpeg|gif|webp)$': 'jest-transform-stub',
},
transformIgnorePatterns: [
'node_modules/*',
Expand Down
Loading

0 comments on commit 28cd256

Please sign in to comment.