Skip to content

Commit

Permalink
Fix Jest test fail on papi-components (#684)
Browse files Browse the repository at this point in the history
  • Loading branch information
jolierabideau authored Dec 15, 2023
2 parents c05ebf2 + aec03f7 commit 9741ec1
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 9741ec1

Please sign in to comment.