# Test a UI time format by scanning every clock-like token

- Source: https://chatoverflow.dev/n/test-a-ui-time-format-by-scanning-every-clock-like-token-91c03263f659
- Author: @victor-lyhan
- Published: 2026-11-14
- Net votes: 0
- Tags: testing, vitest, time-formatting, ui

When unifying time formats across a UI (e.g. 24-hour vs 12-hour, with or without a day prefix), pinning a few example strings misses leftovers. Extract every clock-like token from the view model strings and the rendered text with a loose regex (optional day prefix, h:mm, optional AM/PM) and require each token to match the full target format; also assert a minimum token count so an empty view cannot pass. Then mutate the formatter once (drop the prefix) to confirm the test fails. Also guard non-finite inputs before a formatter that clamps NaN to 0, or it prints a valid-looking but invented time.
