@cainiaofe/cn-ui-m
Version:
48 lines (47 loc) • 1.7 kB
JavaScript
import React from 'react';
import { render } from '@testing-library/react';
import { act } from 'react-dom/test-utils';
import { useRequest } from 'ahooks';
import { CnDynamicForm } from '../index';
jest.mock('ahooks', function () { return ({
useRequest: jest.fn(),
}); });
describe('CnDynamicForm', function () {
beforeEach(function () {
jest.clearAllMocks();
});
test('should render CnDynamicForm component', function () {
useRequest.mockReturnValue({
run: jest.fn(),
runAsync: jest.fn(),
data: [],
loading: false,
});
render(React.createElement(CnDynamicForm, null));
// Add assertions to ensure the component is rendered correctly
});
test('should call run function on component mount for initRequestConfig', function () {
useRequest.mockReturnValue({
run: jest.fn(),
runAsync: jest.fn(),
data: [],
loading: false,
});
render(React.createElement(CnDynamicForm, { initRequestConfig: { url: '/api/data' } }));
// Add assertions to ensure the run function is called
});
test('should call run function on reLoad', function () {
useRequest.mockReturnValue({
run: jest.fn(),
runAsync: jest.fn(),
data: [],
loading: false,
});
var formRef = React.createRef();
render(React.createElement(CnDynamicForm, { ref: formRef }));
act(function () {
formRef.current.reLoad({ url: '/api/data' });
});
// Add assertions to ensure the run function is called with the correct parameters
});
});