这可能是由于测试环境中缺少某些设置或依赖项导致的。最好的解决方案是在测试环境中模拟按钮的点击事件,以确保表单可以正常工作。
代码示例:
import { fireEvent, render } from '@testing-library/react';
describe('Form', () => {
test('submit button should work', () => {
const handleSubmit = jest.fn();
const { getByText, getByLabelText } = render(