Skip to content

Wait function not working as expected after testing-library-dom update  #290

@davidmateoc

Description

@davidmateoc

Description
New version of testing-library-dom is deprecating wait function for waitFor, breaking some existent tests using a previous version (“6.14.0”).

Could be due to this change:

Previously, wait was a wrapper around wait-for-expect and used polling instead of a MutationObserver to look for changes. It is now an alias to waitFor and will be removed in a future release.

This causes the following error when trying to use the wait/waitFor function for an element that needs to appear in the browser:

         92 |  if (typeof window === 'undefined') {
       > 93 |    throw new Error('Could not find default container'); 

Steps to reproduce:

  1. Use the wait/waitFor function for an element in the page
    Example:
    await waitFor(async () => t.expect(findByRole('table')).eql(vehiclesToBeDeleted.length))

Expected behavior
Behavior of wait function is not changed and still can be used to wait for browser elements.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: macOS 10.15.7
  • Browser: Chrome
  • Version 91.0.4472.77

Additional context
The same test passes if testing-library-dom (“6.14.0”) is used instead.

Error logs:

   1) Error: Could not find default container

      Browser: Chrome 91.0.4472.77 / macOS 10.15.7

         88 |exports.clearTimeout = clearTimeoutFn;
         89 |
         90 |function getDocument() {
         91 |  /* istanbul ignore if */
         92 |  if (typeof window === 'undefined') {
       > 93 |    throw new Error('Could not find default container');
         94 |  }
         95 |
         96 |  return window.document;
         97 |}
         98 |

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions