Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

autoFocus not being applied #27

Closed
mischnic opened this issue Aug 25, 2020 · 1 comment
Closed

autoFocus not being applied #27

mischnic opened this issue Aug 25, 2020 · 1 comment

Comments

@mischnic
Copy link
Contributor

  • preact-testing-library version: 2.0.0
  • preact version: 10.4.7
  • node version: 14
  • npm (or yarn) 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
Copy link
Contributor Author

mischnic commented Sep 8, 2020

Likely actually caused by jsdom/jsdom#3041...

@nickserv nickserv closed this as completed Nov 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants