-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Closed
Description
@testing-library/react
version: 11.2.2- Testing Framework and version:
jest@26.6.3
- DOM Environment: default
jsdom
shipped witjest
Relevant code or config:
import * as React from "react";
export default function App({ onClick }) {
return (
<form
className="App"
data-testid="form"
onSubmit={(e) => e.preventDefault()}
>
<input type="text" data-testid="test" />
<button data-testid="button" onClick={onClick}>
click
</button>
</form>
);
}
What you did:
I had a bug related to the fact that buttons inside of form implicitly get the submit
type and get clicked on form submit. I wrote the test to capture this behaviour:
describe("test suite", async () => {
it("test clause", async () => {
const a = jest.fn();
render(<App onClick={a} />);
fireEvent.submit(screen.getByTestId("form"));
expect(a).toBeCalled();
});
});
What happened:
The test failed with message
expect(jest.fn()).toBeCalled()
Expected number of calls: >= 1
Received number of calls: 0
Reproduction:
https://codesandbox.io/s/react-testing-library-playground-forked-0ki4g
Is this a react-testing-library
or underlying jsdom
issue?
Metadata
Metadata
Assignees
Labels
No labels