Skip to content

Commit

Permalink
force jest to read papi-components es module instead of cjs, remove m…
Browse files Browse the repository at this point in the history
…ock papi-components
  • Loading branch information
Jolie Rabideau authored and Jolie Rabideau committed Dec 15, 2023
1 parent c05ebf2 commit aec03f7
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 26 deletions.
1 change: 1 addition & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const config: Config = {
...pathsToModuleNameMapper(compilerOptions.paths, {
prefix: '<rootDir>/src',
}),
'^papi-components$': '<rootDir>/node_modules/papi-components/dist/index.es.js',
},
testEnvironment: 'jsdom',
testEnvironmentOptions: {
Expand Down
13 changes: 0 additions & 13 deletions src/__tests__/app.component.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
20 changes: 20 additions & 0 deletions src/__tests__/button.component.test.tsx
Original file line number Diff line number Diff line change
@@ -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(<Button>{buttonText}</Button>);
expect(getByText(buttonText)).toBeInTheDocument();
});

it('handles click event correctly', () => {
const handleClick = jest.fn();
const { getByText } = render(<Button onClick={handleClick}>Click me</Button>);

fireEvent.click(getByText('Click me'));

expect(handleClick).toHaveBeenCalledTimes(1);
});
});
Original file line number Diff line number Diff line change
@@ -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';
Expand Down

0 comments on commit aec03f7

Please sign in to comment.