Page MenuHomePhabricator

Unit tests: Add awaits to all waitFor statements in jest tests
Closed, ResolvedPublic

Description

Description

In our frontend tests, we often use waitFor to wrap expectations that might take their time. waitFor returns a promise that must be awaited.
https://testing-library.com/docs/dom-testing-library/api-async/

In some old tests, we are using waitFor without waiting for the promise (without having "await" before waitFor), which sometimes results on undetected failures.

Desired behavior/Acceptance criteria

  • all waitFor calls in our tests should be preceded by await
  • if tests had undetected failures, they should be fixed

Completion checklist

Event Timeline

gengh renamed this task from Jest: Add awaits to al waitFor statements in jest tests to Unit tests: Add awaits to al waitFor statements in jest tests.Feb 22 2024, 11:23 AM
gengh created this task.
Jdforrester-WMF renamed this task from Unit tests: Add awaits to al waitFor statements in jest tests to Unit tests: Add awaits to all waitFor statements in jest tests.Feb 22 2024, 5:47 PM
Jdforrester-WMF triaged this task as Medium priority.
Jdforrester-WMF moved this task from To triage to Backlog on the Abstract Wikipedia team board.

Hello! What is the best way to know/verify this:

if tests had undetected failures, they should be fixed

Change #1018785 had a related patch set uploaded (by Ecarg; author: jenkins-bot):

[mediawiki/extensions/WikiLambda@master] Use correct async testing

https://gerrit.wikimedia.org/r/1018785

Change #1018791 had a related patch set uploaded (by Ecarg; author: Ecarg):

[mediawiki/extensions/WikiLambda@master] Update async tests to correctly use await

https://gerrit.wikimedia.org/r/1018791

Change #1018785 abandoned by Ecarg:

[mediawiki/extensions/WikiLambda@master] Use correct async testing

Reason:

https://gerrit.wikimedia.org/r/1018785

Hello! What is the best way to know/verify this:

if tests had undetected failures, they should be fixed

Just by adding the await/async syntax and running the tests again :)

I started fixing non-awaited waitFor calls as I encountered them, and I sometimes observed that a failing test inside of a non-awaited waitFor would not be detected, so the test would return a false positive. Only after adding the "await" statement and declaring the test as "async" I could see that the inner "expect" was actually failing.

Your fix looks good to me!

Change #1018791 merged by jenkins-bot:

[mediawiki/extensions/WikiLambda@master] Update async tests to correctly use await

https://gerrit.wikimedia.org/r/1018791