Skip to content

querySelectorAll is not a function when being called by getByTestId #537

Description

@Nubzor

In the beginning, I would like to thank you for the time you folks put to develop and maintain the library.

I face an issue related to missing .querySelectorAll function while calling getByTestId method which is odd because when I check the object property then I can see that the function exists 🤷

Code example:

import Loader from "./Loader.svelte";

describe("Loader component", () => {
  test("should render component correctly", () => {
    const { container } = render(Loader);

    console.log(typeof container.querySelectorAll)

    expect(container).toContainElement(getByTestId("spinner"));
    expect(container).toBeVisible();
  });
});

Output:

  Loader component
    × should render component correctly (22ms)

  ● Loader component › should render component correctly

    TypeError: container.querySelectorAll is not a function

> 10 |     expect(container).toContainElement(getByTestId('spinner'));

-------

Test Suites: 2 failed, 2 total
Tests:       1 failed, 1 total
Snapshots:   0 total
Time:        3.162s
Ran all test suites matching /src/i.
  console.log     
    Log:  function

There is a list of dependencies and their versions:

    ...
    "@testing-library/jest-dom": "^5.5.0",
    "@testing-library/svelte": "^3.0.0",
    ...
    "jest": "^25.4.0",
    "jest-transform-svelte": "^2.1.1",
    "svelte": "^3.21.0",

Node: 12.16.1 on Windows 10

I am not sure whether this is a bug or I missed something during the configuration, any tips would be appreciated.

Greetings,

Mateusz

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions