forked from sombochea/verdaccio-ui
refactor: adds missing test spec for button click in not found (#222)
* refactor: adds missing test spec for button click in not found * refactor: improves test description
This commit is contained in:
parent
a38b93e127
commit
531295a6d0
@ -27,7 +27,7 @@ const StyledHeading = styled(Typography)({
|
||||
const NotFound: React.FC = () => {
|
||||
const history = useHistory();
|
||||
|
||||
const handleGomHome = useCallback(() => {
|
||||
const handleGoHome = useCallback(() => {
|
||||
history.push('/');
|
||||
}, [history]);
|
||||
|
||||
@ -37,7 +37,7 @@ const NotFound: React.FC = () => {
|
||||
<StyledHeading className="not-found-text" variant="h4">
|
||||
{NOT_FOUND_TEXT}
|
||||
</StyledHeading>
|
||||
<Button onClick={handleGomHome} variant="contained">
|
||||
<Button onClick={handleGoHome} variant="contained">
|
||||
{GO_TO_HOME_PAGE}
|
||||
</Button>
|
||||
</Box>
|
||||
|
@ -1,8 +1,8 @@
|
||||
import React from 'react';
|
||||
import { BrowserRouter as Router } from 'react-router-dom';
|
||||
import { render } from '@testing-library/react';
|
||||
import { render, fireEvent } from '@testing-library/react';
|
||||
|
||||
import NotFound from './NotFound';
|
||||
import NotFound, { GO_TO_HOME_PAGE } from './NotFound';
|
||||
|
||||
describe('<NotFound /> component', () => {
|
||||
test('should load the component in default state', () => {
|
||||
@ -13,5 +13,17 @@ describe('<NotFound /> component', () => {
|
||||
);
|
||||
expect(container.firstChild).toMatchSnapshot();
|
||||
});
|
||||
test.todo('Test Button Click');
|
||||
test('go to Home Page button click', () => {
|
||||
const spy = jest.spyOn(React, 'useCallback');
|
||||
const { getByText } = render(
|
||||
<Router>
|
||||
<NotFound />
|
||||
</Router>
|
||||
);
|
||||
|
||||
const node = getByText(GO_TO_HOME_PAGE);
|
||||
fireEvent.click(node);
|
||||
|
||||
expect(spy).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user