Skip to content

infinite loop when DOM mutation happens in waitFor callback #808

Open
@drudv

Description

@drudv

Jest hangs on the following sample test:

const { waitFor } = require("@testing-library/dom");

describe("test", () => {
  it("test", async () => {
    let value = 1;

    setTimeout(() => {
      value = 2;
    });

    await waitFor(() => {
      // both these lines are important: it's necessary to do a mutation and to fail in the first iteration
      // It works normally, if we comment one of these lines
      document.body.setAttribute("data-something", 'whatever');
      expect(value).toEqual(2);
    });

    console.log("execution never comes here");
  });
});

Two conditions have to be met:

  • there should be a DOM mutation in waitFor callback
  • first execution of waitFor callback should fail

Expected result:
waitFor should resolve the promise after a successful iteration regardless whether there were DOM mutations or not

Current result:
waitFor calls the callback infinitely even if subsequent iterations don't throw any exception.

Environment:
@testing-library/[email protected]
[email protected]

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingdocumentationAn update needs to be made to documentation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions