From e651e9c7975fa033045973f89114f1fe27f11af2 Mon Sep 17 00:00:00 2001 From: Yusuf Seyrek Date: Tue, 30 May 2023 12:16:13 +0300 Subject: [PATCH] feat: store and component mocks setup (#237) * feat: store and component mocks setup * feat: more examples --- __mocks__/store.js | 23 +++++++++++++ __tests__/Footer.test.tsx | 12 +++---- __tests__/components/Button/Button.test.tsx | 30 ++++++++++++++-- .../components/CircularProgress.test.tsx | 34 +++++++++++++++++++ jest.config.js | 6 +++- src/components/CircularProgress.tsx | 6 +--- src/store/index.ts | 8 ++++- src/utils/testing.tsx | 7 ++++ test.setup.js | 1 - 9 files changed, 109 insertions(+), 18 deletions(-) create mode 100644 __mocks__/store.js create mode 100644 __tests__/components/CircularProgress.test.tsx create mode 100644 src/utils/testing.tsx diff --git a/__mocks__/store.js b/__mocks__/store.js new file mode 100644 index 00000000..0ceb53cc --- /dev/null +++ b/__mocks__/store.js @@ -0,0 +1,23 @@ +jest.mock('store', () => { + let state = {} + + const mockUseStore = (selectorFn) => { + return selectorFn(state) + } + + mockUseStore.setState = (newState) => { + state = { + ...state, + ...newState, + } + } + + mockUseStore.clearState = () => { + state = {} + } + + return { + __esModule: true, + default: mockUseStore, + } +}) diff --git a/__tests__/Footer.test.tsx b/__tests__/Footer.test.tsx index 650e253f..d68cd3a8 100644 --- a/__tests__/Footer.test.tsx +++ b/__tests__/Footer.test.tsx @@ -1,16 +1,14 @@ -import { shallow } from 'enzyme' +import { render } from '@testing-library/react' import Footer from 'components/Footer' -import Text from 'components/Text' import packageJSON from '../package.json' describe('