Skip to content

[Flaky Test] SubscriptionUtils › isUserOnFreeTrial › should return true if the current date is on the same date of free trial start date #95394

Description

@MelvinBot

Flaky Test

tests/unit/SubscriptionUtilsTest.ts intermittently fails on:

SubscriptionUtils › isUserOnFreeTrial › should return true if the current date is on the same date of free trial start date

FAIL tests/unit/SubscriptionUtilsTest.ts
  ● SubscriptionUtils › isUserOnFreeTrial › should return true if the current date is on the same date of free trial start date
      at Object.toBeTruthy (tests/unit/SubscriptionUtilsTest.ts:200:76)

Test Suites: 1 failed, 116 passed, 117 total
Tests:       1 failed, 2 skipped, 1917 passed, 1920 total

Seen on: Expensify/App#93054 — test (job 7) (unrelated PR; the failure has nothing to do with that PR's changes).

Likely cause

The test depends on the real system clock rather than fake timers. It captures firstDayFreeTrial from new Date() and then calls isUserOnFreeTrial(...), which re-reads new Date() at call time:

tests/unit/SubscriptionUtilsTest.ts:192-201

Because the two new Date() reads happen at slightly different moments (and can straddle a second/minute/day boundary), the free-trial window comparison can evaluate to false, so the toBeTruthy() assertion fails non-deterministically.

Suggested fix

Freeze time in this suite (e.g. jest.useFakeTimers().setSystemTime(...) or inject a fixed "now") so the boundary date/time comparisons are deterministic, then restore real timers in teardown. The same clock-dependent pattern applies to the sibling isUserOnFreeTrial cases, so consider stabilizing them together.

This is a pre-existing flaky test, not a regression from any specific PR.

Metadata

Metadata

Assignees

Labels

ImprovementItem broken or needs improvement.ReviewingHas a PR in reviewWeeklyKSv2

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions