Код: Выделить всё
import React from 'react';
//onDownload defined here
const CustomModal = (state) => {
return (
[url=#] {
event.preventDefault();
onDownload(state.[file_id]);
}}
> {state[file_name}} [/url]
)
};
Код: Выделить всё
import React from 'react';
import { Provider } from 'react-redux';
import { render, screen, fireEvent, cleanup } from '@testing-library/react';
import '@testing-library/jest-dom';
describe('CustomModal', () => {
let store;
describe('render', () => {
beforeEach(() => {
store = configureStore(
{
import: {
state: {
file_isas_id: 123456789,
file_name: 'test_file.xlsx',
},
},
},
);
rendered = render(
,
});
afterEach(() => {
cleanup();
});
it('should call the onDownload when the download link is clicked', () => {
const onDownload= jest.fn();
fireEvent.click(screen.getByText('test_file.xlsx'));
expect(onDownload).toHaveBeenCalledTimes(1);
});
Подробнее здесь: https://stackoverflow.com/questions/793 ... ng-library