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:
Ayush Sharma 2019-10-26 13:13:47 +02:00 committed by GitHub
parent a38b93e127
commit 531295a6d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 5 deletions

View File

@ -27,7 +27,7 @@ const StyledHeading = styled(Typography)({
const NotFound: React.FC = () => { const NotFound: React.FC = () => {
const history = useHistory(); const history = useHistory();
const handleGomHome = useCallback(() => { const handleGoHome = useCallback(() => {
history.push('/'); history.push('/');
}, [history]); }, [history]);
@ -37,7 +37,7 @@ const NotFound: React.FC = () => {
<StyledHeading className="not-found-text" variant="h4"> <StyledHeading className="not-found-text" variant="h4">
{NOT_FOUND_TEXT} {NOT_FOUND_TEXT}
</StyledHeading> </StyledHeading>
<Button onClick={handleGomHome} variant="contained"> <Button onClick={handleGoHome} variant="contained">
{GO_TO_HOME_PAGE} {GO_TO_HOME_PAGE}
</Button> </Button>
</Box> </Box>

View File

@ -1,8 +1,8 @@
import React from 'react'; import React from 'react';
import { BrowserRouter as Router } from 'react-router-dom'; 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', () => { describe('<NotFound /> component', () => {
test('should load the component in default state', () => { test('should load the component in default state', () => {
@ -13,5 +13,17 @@ describe('<NotFound /> component', () => {
); );
expect(container.firstChild).toMatchSnapshot(); 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();
});
}); });