`autoFocus` not being applied
mischnic opened this issue · 1 comments
mischnic commented
preact-testing-library
version: 2.0.0preact
version: 10.4.7node
version: 14npm
(oryarn
) version: .22.4
Relevant code or config
import React from "preact/compat";
import { render, fireEvent } from "@testing-library/preact";
// works:
// import React from "react";
// import { render, fireEvent } from "@testing-library/react";
test("test", () => {
const { getByTestId } = render(
<div>
<input data-testid="input" autoFocus />
</div>
);
expect(document.activeElement).toBe(getByTestId("input"));
});
What you did:
See code
What happened:
FAIL ./test.js
✕ test (25 ms)
● test
expect(received).toBe(expected) // Object.is equality
- Expected - 0
+ Received + 6
+ <body>
+ <div>
+ <div>
<input
autofocus="true"
data-testid="input"
/>
+ </div>
+ </div>
+ </body>
12 | );
13 |
> 14 | expect(document.activeElement).toBe(getByTestId("input"));
| ^
15 | });
16 |
at Object.<anonymous> (test.js:14:34)
Reproduction repository:
https://codesandbox.io/s/beautiful-cannon-gw4ee?file=/src/index.test.js
Problem description:
Apparently, the <input autoFocus>
element isn't focused. The example works when changing out the imports to use React.
Suggested solution:
Autofocus the element....
mischnic commented
Likely actually caused by jsdom/jsdom#3041...