Skip to content

[Due for payment 2025-09-02] [$125] Fix flaky test UnreadIndicatorsTest #66037

Closed

Description

@mountiny

This tests is flaky on main, please, identify the RCA and try to identify the pattern that we could try to avoid in other places. Lets fix this same issue in other tests if present and propose if there is some guard we could put in place to avoid this.

  ● Unread Indicators › Do not display the new line indicator when tracking an expense on self DM while offline

    expect(received).toHaveLength(expected)

    Expected length: 0
    Received length: 1
    Received array:  [{"_fiber": [FiberNode]}]

      672 |         const newMessageLineIndicatorHintText = translateLocal('accessibilityHints.newMessageLineIndicator');
      673 |         const unreadIndicator = screen.queryAllByLabelText(newMessageLineIndicatorHintText);
    > 674 |         expect(unreadIndicator).toHaveLength(0);
          |                                 ^
      675 |     });
      676 |     it('Mark the chat as unread on clicking "Mark as unread" on an item in LHN when the last message of the chat was deleted by another user', async () => {
      677 |         await signInAndGetAppWithUnreadChat();

      at Object.toHaveLength (tests/ui/UnreadIndicatorsTest.tsx:674:33)
      at asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:17)
      at _next (node_modules/@babel/runtime/helpers/asyncToGenerator.js:17:9)
Issue OwnerCurrent Issue Owner: @abekkala

Activity

  1. added
    ExternalAdded to denote the issue can be worked on by a contributor
    BugSomething is broken. Auto assigns a BugZero manager.
    on Jul 14, 2025
  2. added
    Help WantedApply this label when an issue is open to proposals by contributors
    on Jul 14, 2025
  3. melvin-bot commented on Jul 14, 2025

    @melvin-bot

    Triggered auto assignment to Contributor-plus team member for initial proposal review - @getusha (External)

  4. melvin-bot commented on Jul 14, 2025

    @melvin-bot

    Triggered auto assignment to @maddylewis (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details. Please add this bug to a GH project, as outlined in the SO.

  5. changed the title [-]Fix flaky test UnreadIndicatorsTest[/-] [+][$125] Fix flaky test UnreadIndicatorsTest[/+] on Jul 14, 2025
  6. melvin-bot commented on Jul 14, 2025

    @melvin-bot

    ⚠️ Could not update price automatically because there is no linked Upwork Job ID. The BZ team member will need to update the price manually in Upwork.

  7. nkdengineer commented on Jul 14, 2025

    @nkdengineer
    Contributor

    Proposal

    Please re-state the problem that we are trying to solve in this issue.

    Fix flaky test UnreadIndicatorsTest

    What is the root cause of that problem?

    1. We don't return a promise to wait for the Onyx clear to be complete

    1. We can have the same problem as here when calling signInWithTestUser and rendering the sidebar

    What changes do you think we should make in order to solve the problem?

    We should return a promise here and also set the fetch to our mock fetch

    beforeEach(() => {
        jest.clearAllMocks();
    
        global.fetch = TestHelper.getGlobalFetchMock();
        // Unsubscribe to pusher channels
        PusherHelper.teardown();
    
        return Onyx.clear().then(waitForBatchedUpdates);
    });
    

    What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?

    None

    What alternative solutions did you explore? (Optional)

    NA

    Reminder: Please use plain English, be brief and avoid jargon. Feel free to use images, charts or pseudo-code if necessary. Do not post large multi-line diffs or write walls of text. Do not create PRs unless you have been hired for this job.

  8. nabi-ebrahimi commented on Jul 14, 2025

    @nabi-ebrahimi

    Proposal

    Please re-state the problem that we are trying to solve in this issue.

    Fix flaky test UnreadIndicatorsTest

    What is the root cause of that problem?

    • Race Condition Between State Updates and Assertion
      The app heavily relies on async state updates, which may not be flushed by the time the test reaches the assertion.

    • Test Uses Static Queries Instead of waitFor
      The test uses screen.queryAllByLabelText without waiting for the DOM to settle.
      This is risky, especially with asynchronous render cycles or delayed state propagation.

      Using synchronous assertions without awaiting side effects can easily lead to flakiness.

    What changes do you think we should make in order to solve the problem?

    Use waitFor when querying elements affected by state or side effects:

    await waitFor(() => {
        expect(screen.queryAllByLabelText(newMessageLineIndicatorHintText)).toHaveLength(0);
    });

    This ensures that React Native's async rendering and Onyx-based updates complete before assertion.

    Audit similar tests for risky direct assertions:

    • Search tests in the suite using screen.queryBy... or screen.queryAllBy... with immediate expect(...).toHaveLength(0).
    • Replace with waitFor where state can be async.

    We can consider introducing a shared test utility:

    export const waitForUnreadIndicatorToDisappear = async (label: string) => {
        await waitFor(() => {
            expect(screen.queryAllByLabelText(label)).toHaveLength(0);
        });
    };

    What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?

    What alternative solutions did you explore? (Optional)

  9. getusha commented on Jul 14, 2025

    @getusha
    Contributor

    @nkdengineer @nabi-ebrahimi it's not a new test case your RCA fails to explain why it suddenly started to fail

  10. nkdengineer commented on Jul 14, 2025

    @nkdengineer
    Contributor

    @getusha The test will fail sometimes. It's based on Onyx.clear is done before the next test or not. Because we don't return a promise in beforeEach, the next test can be executed before Onyx.clear is complete.

  11. getusha commented on Jul 14, 2025

    @getusha
    Contributor

    @getusha The test will fail sometimes. It's based on Onyx.clear is done before the next test or not. Because we don't return a promise in beforeEach, the next test can be executed before Onyx.clear is complete.

    Is there a way to make sure we don't forget to return the promise when there's an Onyx operation in a test case?

  12. 31 remaining items

  13. melvin-bot commented on Aug 26, 2025

    @melvin-bot

    @getusha @abekkala The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed. Please copy/paste the BugZero Checklist from here into a new comment on this GH and complete it. If you have the K2 extension, you can simply click: [this button]

  14. abekkala commented on Aug 26, 2025

    @abekkala
    Contributor

    PAYMENT SUMMARY FOR SEPT 02

    • Fix: @nkdengineer [$125, if no regressions] payment via Upwork OFFER
    • PR Review: @getusha [$125, if no regressions] payment via NewDot
      please complete checklist
  15. abekkala commented on Sep 2, 2025

    @abekkala
    Contributor

    @nkdengineer please accept the Upwork offer and I can get that sent today - thanks!

  16. nkdengineer commented on Sep 2, 2025

    @nkdengineer
    Contributor

    @abekkala Offer was accepted, thanks!

  17. abekkala commented on Sep 2, 2025

    @abekkala
    Contributor

    @nkdengineer payment sent and contract ended - thank you! 🎉

    @getusha please complete the checklist and we can close this one out! Thanks!

  18. melvin-bot commented on Sep 2, 2025

    @melvin-bot

    Payment Summary

    Upwork Job

    BugZero Checklist (@abekkala)

    • (if NewFeature) I have created a PR for any necessary HelpDot updates, or I confirmed no updates are necessary.
    • I have verified the correct assignees and roles are listed above and updated the necessary manual offers
    • I have verified that there are no duplicate or incorrect contracts on Upwork for this job (https://www.upwork.com/ab/applicants//hired)
    • I have verified the PR was not reverted
    • I have applied any discounts due to bugs/regressions introduced by this PR
    • I have paid out the Upwork contracts or cancelled the ones that are incorrect
    • I have verified the payment summary above is correct
  19. abekkala commented on Sep 3, 2025

    @abekkala
    Contributor

    @getusha bumping for the checklist - thanks!

  20. abekkala commented on Sep 4, 2025

    @abekkala
    Contributor

    @getusha can you complete the checklist so we can close this one out - thanks!

  21. getusha commented on Sep 4, 2025

    @getusha
    Contributor

    BugZero Checklist:

    • [Contributor] Classify the bug:
    Bug classification

    Source of bug:

    • 1a. Result of the original design (eg. a case wasn't considered)
    • 1b. Mistake during implementation
    • 1c. Backend bug
    • 1z. Other:

    Where bug was reported:

    • 2a. Reported on production (eg. bug slipped through the normal regression and PR testing process on staging)
    • 2b. Reported on staging (eg. found during regression or PR testing)
    • 2d. Reported on a PR
    • 2z. Other:

    Who reported the bug:

    • 3a. Expensify user
    • 3b. Expensify employee
    • 3c. Contributor
    • 3d. QA
    • 3z. Other:

    We don’t need a new test. This is not a bug, but a unit test inconsistency.

    Regression Test Proposal Template
    • [BugZero Assignee] Create a GH issue for creating/updating the regression test once above steps have been agreed upon.

      Link to issue:

  22. getusha commented on Sep 4, 2025

    @getusha
    Contributor

    @getusha can you complete the checklist so we can close this one out - thanks!

    Done, thanks!

  23. abekkala commented on Sep 5, 2025

    @abekkala
    Contributor

    posting payment summary once more for better visibility:

    PAYMENT SUMMARY FOR SEPT 02

    • Fix: @nkdengineer [$125] payment via Upwork - PAID and contract ended, thanks again! 🎉
    • PR Review: @getusha [$125] payment via NewDot
  24. flaviadefaria commented on Oct 2, 2025

    @flaviadefaria
    Contributor

    $125 approved for @getusha

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Awaiting PaymentAuto-added when associated PR is deployed to productionBugSomething is broken. Auto assigns a BugZero manager.DailyKSv2ExternalAdded to denote the issue can be worked on by a contributor

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions