From aec03f742ea6658ff87f9755dfdbf86c6a0128d1 Mon Sep 17 00:00:00 2001 From: Jolie Rabideau Date: Fri, 15 Dec 2023 16:21:15 -0500 Subject: [PATCH] force jest to read papi-components es module instead of cjs, remove mock papi-components --- jest.config.ts | 1 + src/__tests__/app.component.test.tsx | 13 ------------ src/__tests__/button.component.test.tsx | 20 +++++++++++++++++++ .../platform-dock-layout.component.test.ts | 13 ------------ 4 files changed, 21 insertions(+), 26 deletions(-) create mode 100644 src/__tests__/button.component.test.tsx diff --git a/jest.config.ts b/jest.config.ts index 1d800abd36..70e4631bb9 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -18,6 +18,7 @@ const config: Config = { ...pathsToModuleNameMapper(compilerOptions.paths, { prefix: '/src', }), + '^papi-components$': '/node_modules/papi-components/dist/index.es.js', }, testEnvironment: 'jsdom', testEnvironmentOptions: { diff --git a/src/__tests__/app.component.test.tsx b/src/__tests__/app.component.test.tsx index f309601db9..115524d6fa 100644 --- a/src/__tests__/app.component.test.tsx +++ b/src/__tests__/app.component.test.tsx @@ -39,19 +39,6 @@ jest.mock('@renderer/components/docking/platform-dock-layout.component', () => ( __esModule: true, default: /** ParanextDockLayout Mock */ () => undefined, })); -// Mock all of the papi-components because they should test themselves -jest.mock( - 'papi-components', - () => - new Proxy( - {}, - { - get() { - return function MockComponent() {}; - }, - }, - ), -); describe('App', () => { it('should render', async () => { diff --git a/src/__tests__/button.component.test.tsx b/src/__tests__/button.component.test.tsx new file mode 100644 index 0000000000..0eb06071d2 --- /dev/null +++ b/src/__tests__/button.component.test.tsx @@ -0,0 +1,20 @@ +import { render, fireEvent } from '@testing-library/react'; +import { Button } from 'papi-components'; +import '@testing-library/jest-dom/extend-expect'; + +describe('Button', () => { + it('renders button text correctly', () => { + const buttonText = 'Click me'; + const { getByText } = render(); + expect(getByText(buttonText)).toBeInTheDocument(); + }); + + it('handles click event correctly', () => { + const handleClick = jest.fn(); + const { getByText } = render(); + + fireEvent.click(getByText('Click me')); + + expect(handleClick).toHaveBeenCalledTimes(1); + }); +}); diff --git a/src/renderer/components/docking/platform-dock-layout.component.test.ts b/src/renderer/components/docking/platform-dock-layout.component.test.ts index caebc0310b..b430cf0394 100644 --- a/src/renderer/components/docking/platform-dock-layout.component.test.ts +++ b/src/renderer/components/docking/platform-dock-layout.component.test.ts @@ -1,18 +1,5 @@ /* eslint-disable import/first */ jest.mock('../../../shared/services/logger.service'); -// Mock all of the papi-components because they should test themselves -jest.mock( - 'papi-components', - () => - new Proxy( - {}, - { - get() { - return function MockComponent() {}; - }, - }, - ), -); import DockLayout, { FloatPosition } from 'rc-dock'; import { anything, instance, mock, verify, when } from 'ts-mockito';