Skip to content

date: 2026-06-19 tags: [testing, pest-browser, clock, time] status: active graduated_to:

A Pest browser test's JS clock isn't faked by travelTo — assert clock-independent values

Symptom — A browser test froze Laravel's clock with $this->travelTo('2026-06-15') and a task with a 2026-06-25 deadline, then asserted the rendered In 10 days • 25th June. It failed: the page showed In 6 days • 25th June.

Root causetravelTo / setTestNow only fake PHP's clock. The relative count is computed client-side in the headless browser from new Date(), which reads the browser's real wall-clock — unaffected by the PHP time travel. So any JS-computed relative date (In N days, N days ago) is non-deterministic in a browser test.

Fix — Assert only the clock-independent part. tests/Browser/DeadlinesSectionTest.php now asserts the concrete formatted date (25th June), not the relative prefix. (PR #589.)

Guard — Convention, scoped to tests/Browser/**: never assert a JS-computed relative-to-now value in a browser test; assert a fixed, clock-independent rendering instead (or drive the relative logic from a feature/unit test where you control the input). This is the inverse of the existing PHP clock-determinism rule in testing.md (which keeps app/ from reading the clock); if it recurs, graduate this line into testing.md's browser-test section.