1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-01 21:57:06 +01:00
metamask-extension/ui/components/multichain/token-list-item/token-list-item.test.js

58 lines
1.5 KiB
JavaScript
Raw Normal View History

2023-03-23 11:08:33 +01:00
import React from 'react';
import configureMockStore from 'redux-mock-store';
import { fireEvent } from '@testing-library/react';
import { renderWithProvider } from '../../../../test/lib/render-helpers';
import { TokenListItem } from '.';
2023-03-23 11:08:33 +01:00
const state = {
metamask: {
providerConfig: {
2023-03-23 11:08:33 +01:00
ticker: 'ETH',
nickname: '',
chainId: '0x1',
type: 'mainnet',
},
useTokenDetection: false,
nativeCurrency: 'ETH',
},
};
describe('TokenListItem', () => {
2023-03-23 11:08:33 +01:00
const props = {
onClick: jest.fn(),
};
it('should render correctly', () => {
const store = configureMockStore()(state);
const { getByTestId, container } = renderWithProvider(
<TokenListItem />,
2023-03-23 11:08:33 +01:00
store,
);
expect(getByTestId('multichain-token-list-item')).toBeDefined();
expect(container).toMatchSnapshot();
});
it('should render with custom className', () => {
const store = configureMockStore()(state);
const { getByTestId } = renderWithProvider(
<TokenListItem className="multichain-token-list-item-test" />,
2023-03-23 11:08:33 +01:00
store,
);
expect(getByTestId('multichain-token-list-item')).toHaveClass(
'multichain-token-list-item-test',
);
});
it('handles click action and fires onClick', () => {
const store = configureMockStore()(state);
const { queryByTestId } = renderWithProvider(
<TokenListItem {...props} />,
2023-03-23 11:08:33 +01:00
store,
);
fireEvent.click(queryByTestId('multichain-token-list-button'));
expect(props.onClick).toHaveBeenCalled();
});
});