Fix timezone service spec in local timezones#23209
Open
myabc wants to merge 1 commit into
Open
Conversation
Mock the guessed timezone when the configuration has no explicit timezone so the UTC expectation is deterministic across developer environments.
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a flaky frontend spec in timezone.service.spec.ts that depended on the developer's local machine timezone. When no explicit timezone is configured, TimezoneService falls back to moment.tz.guess(), which previously caused failures in non-UTC environments.
Changes:
- Mock
moment.tz.guess()to returnEtc/UTCwhen no timezone is configured in the test setup. - Restore all mocks via
afterEachto avoid leakage between tests. - Minor reformatting of the
TestBed.configureTestingModuleblock.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ticket
No work package.
What are you trying to accomplish?
Fix a timezone service spec that fails in non-UTC local browser timezones (this is a big annoyance when not working from GMT!)
When no explicit timezone is configured,
TimezoneServicefalls back tomoment.tz.guess(), so the spec must not depend on the developer machine timezone.What approach did you choose and why?
Mock
moment.tz.guess()to returnEtc/UTCfor the no-config case and restore mocks after each test. This keeps production behavior unchanged while making the UTC expectation deterministic. The existing configured-timezone test still covers the non-UTC conversion path.Merge checklist
npm test)