Skip to content

"await wait" elapses timeout in the simplest case #387

Closed
@anuraags

Description

@anuraags
  • react-testing-library version: @testing-library/react@8.0.1
  • react version: react@16.8.1
  • node version: node@10.11.0
  • npm (or yarn) version: npm@6.9.0

Relevant code or config:

import {wait} from '@testing-library/react';

describe('simple await', ()=> {
  it('returns straight away', async ()=> {
    await wait();
  });
});

What you did:

I was trying to implement an await for an expectation to pass and the test kept failing due to timeout. I whittled the code down in order to find the cause and found that even a simple await wait(); would never return.

What happened:

The jest test would simply timeout without returning

Reproduction:

Problem description:

The problem seems to be with the waitWrapper code in wait.js in the @testing-library/dom library. The asyncWrapper awaits on a promise but the inner code doesn't seem to return the promise:

function waitWrapper(...args) {
  return (0, _config.getConfig)().asyncWrapper(() => wait(...args));
}

Suggested solution:

I was able to solve it by changing the above code to:

function waitWrapper(...args) {
  return (0, _config.getConfig)().asyncWrapper(() => {
    return wait(...args);
  });
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions