Skip to content

Commit c3e5ddc

Browse files
committed
refactor(common): fix unit tests
1 parent ceec0ab commit c3e5ddc

File tree

7 files changed

+17
-13
lines changed

7 files changed

+17
-13
lines changed

packages/cardano/src/wallet/lib/__tests__/get-inputs-value.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ describe('Testing getTxInputsValueAndAddress function', () => {
250250
]);
251251

252252
const result = getTxInputsValueAndAddress(
253-
Array.from({ length: 30 }).map((_, index) => ({ index, txId: 'txId1' }) as unknown as Cardano.TxIn),
253+
Array.from({ length: 30 }).map((_, index) => ({ index, txId: 'txId1' } as unknown as Cardano.TxIn)),
254254
{
255255
transactionsByHashes
256256
} as unknown as ChainHistoryProvider,
@@ -285,7 +285,7 @@ describe('Testing getTxInputsValueAndAddress function', () => {
285285
);
286286

287287
const result = getTxInputsValueAndAddress(
288-
Array.from({ length: 30 }).map((_, index) => ({ index: 0, txId: `txId${index}` }) as Cardano.TxIn),
288+
Array.from({ length: 30 }).map((_, index) => ({ index: 0, txId: `txId${index}` } as Cardano.TxIn)),
289289
{
290290
transactionsByHashes
291291
} as unknown as ChainHistoryProvider,

packages/common/src/ui/components/CollapsablePanel/__tests__/CollapsablePanel.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ describe('CollapsablePanel', () => {
2222
);
2323
const clickable = queryByRole('button');
2424
act(() => {
25-
fireEvent.click(clickable);
25+
clickable && fireEvent.click(clickable);
2626
});
2727
expect(queryByTestId('test-content')).toBeInTheDocument();
2828
});

packages/common/src/ui/components/Drawer/__tests__/DrawerNavigation.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ describe('DrawerNavigation', () => {
1515
const { queryByTestId } = render(<DrawerNavigation onArrowIconClick={onClick} />);
1616
const backButton = queryByTestId('navigation-button-arrow');
1717
expect(backButton).toBeInTheDocument();
18-
fireEvent.click(backButton);
18+
backButton && fireEvent.click(backButton);
1919
expect(onClick).toHaveBeenCalled();
2020
});
2121
test('shows close button if on click function is defined', () => {
2222
const onClick = jest.fn();
2323
const { queryByTestId } = render(<DrawerNavigation onCloseIconClick={onClick} />);
2424
const closeButton = queryByTestId('navigation-button-cross');
2525
expect(closeButton).toBeInTheDocument();
26-
fireEvent.click(closeButton);
26+
closeButton && fireEvent.click(closeButton);
2727
expect(onClick).toHaveBeenCalled();
2828
});
2929
test('shows left actions if passed as props instead of back arrow', () => {

packages/common/src/ui/components/Form/Input/__tests__/Input.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ describe('Input', () => {
1515
const input = queryByTestId('input-test');
1616
expect(input).toHaveValue('');
1717
act(() => {
18-
fireEvent.change(input, { target: { value: 'new value' } });
18+
input && fireEvent.change(input, { target: { value: 'new value' } });
1919
});
2020
expect(input).toHaveValue('new value');
2121
expect(onChange).toHaveBeenCalled();

packages/common/src/ui/components/Form/TextArea/__tests__/TextArea.test.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ describe('TextArea', () => {
1515
const area = queryByTestId('text-area-test');
1616
expect(area).toHaveValue('');
1717
act(() => {
18-
fireEvent.change(area, { target: { value: 'new value' } });
18+
area && fireEvent.change(area, { target: { value: 'new value' } });
1919
});
2020
expect(area).toHaveValue('new value');
2121
expect(onChange).toHaveBeenCalled();
@@ -24,7 +24,8 @@ describe('TextArea', () => {
2424
const onBlur = jest.fn();
2525
const { queryByTestId } = render(<TextArea dataTestId="text-area-test" onBlur={onBlur} />);
2626
await waitFor(() => {
27-
fireEvent.blur(queryByTestId('text-area-test'));
27+
const area = queryByTestId('text-area-test');
28+
area && fireEvent.blur(area);
2829
});
2930
expect(onBlur).toHaveBeenCalled();
3031
});

packages/common/src/ui/components/Search/__tests__/Search.test.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,17 @@ describe('Search', () => {
1414
const onInputBlur = jest.fn();
1515
const { queryByTestId } = render(<Search onInputBlur={onInputBlur} />);
1616
act(() => {
17-
fireEvent.blur(queryByTestId('search-input'));
17+
const input = queryByTestId('search-input');
18+
input && fireEvent.blur(input);
1819
});
1920
expect(onInputBlur).toHaveBeenCalled();
2021
});
2122
test('call onInputFocus function prop on search input focus', () => {
2223
const onInputFocus = jest.fn();
2324
const { queryByTestId } = render(<Search onInputFocus={onInputFocus} />);
2425
act(() => {
25-
fireEvent.focus(queryByTestId('search-input'));
26+
const input = queryByTestId('search-input');
27+
input && fireEvent.focus(input);
2628
});
2729
expect(onInputFocus).toHaveBeenCalled();
2830
});
@@ -32,7 +34,7 @@ describe('Search', () => {
3234
const clearButton = queryByTestId('search-clear-button');
3335
expect(clearButton).toBeInTheDocument();
3436
act(() => {
35-
fireEvent.click(clearButton);
37+
clearButton && fireEvent.click(clearButton);
3638
});
3739
expect(onClearButtonClick).toHaveBeenCalled();
3840
});

packages/common/src/ui/components/Toast/__tests__/Toast.test.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ const ToastContainer = ({ text, duration, withProgressBar }: ToastProps) => {
1818
};
1919

2020
describe('Testing TextContent component', () => {
21+
const duration = 10;
2122
const props: ToastProps = {
2223
text: 'test text',
23-
duration: 10,
24+
duration,
2425
withProgressBar: true
2526
};
2627

@@ -82,6 +83,6 @@ describe('Testing TextContent component', () => {
8283

8384
setTimeout(() => {
8485
expect(screen.queryAllByText(props.text)).toHaveLength(0);
85-
}, props.duration + 1);
86+
}, duration + 1);
8687
});
8788
});

0 commit comments

Comments
 (0)