From 531295a6d0d9601e0f772ca126da7d930c791b55 Mon Sep 17 00:00:00 2001 From: Ayush Sharma Date: Sat, 26 Oct 2019 13:13:47 +0200 Subject: [PATCH] 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 --- src/components/NotFound/NotFound.tsx | 4 ++-- src/components/NotFound/Notfound.test.tsx | 18 +++++++++++++++--- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/components/NotFound/NotFound.tsx b/src/components/NotFound/NotFound.tsx index 2f5d290..96d6105 100644 --- a/src/components/NotFound/NotFound.tsx +++ b/src/components/NotFound/NotFound.tsx @@ -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 = () => { {NOT_FOUND_TEXT} - diff --git a/src/components/NotFound/Notfound.test.tsx b/src/components/NotFound/Notfound.test.tsx index 6207de5..f3941ac 100644 --- a/src/components/NotFound/Notfound.test.tsx +++ b/src/components/NotFound/Notfound.test.tsx @@ -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(' component', () => { test('should load the component in default state', () => { @@ -13,5 +13,17 @@ describe(' 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( + + + + ); + + const node = getByText(GO_TO_HOME_PAGE); + fireEvent.click(node); + + expect(spy).toHaveBeenCalled(); + }); });