[Test Improver] Add unit tests for useI18n composable - #104
Draft
github-actions[bot] wants to merge 1 commit into
Draft
[Test Improver] Add unit tests for useI18n composable#104github-actions[bot] wants to merge 1 commit into
github-actions[bot] wants to merge 1 commit into
Conversation
9 tests covering:
- initialization: valid store returns { t } function
- initialization: null/undefined store throws descriptive error
- t(): delegates to stringFor with all args (key, args, raw)
- t(): passes undefined args/raw when omitted
- t(): returns key as fallback when store is null
- t(): logs console.warn when store is null in dev mode
- t(): no warning when store is null outside dev mode
- t(): module-level store is replaced by most recent useI18n call
Uses jest.unmock() + jest.resetModules() to bypass the global
setup mock in jest.setup.js and test the real implementation.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This was referenced Jun 28, 2026
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.
🤖 This PR was created by Test Improver, an automated AI assistant focused on improving test coverage.
Goal and Rationale
shell/composables/useI18n.tsis a key translation composable used throughout the dashboard. It has real branching logic worth testing:storevariable that persists across calls, creating interesting interaction patternst(): returns the key as-is when the store is unavailableconsole.warnonly in dev environmentsDespite being globally mocked in
jest.setup.js(so other tests can use it without a real store), the composable itself had zero dedicated unit tests.Approach
The global mock in
jest.setup.jswould normally prevent direct testing. The solution is to usejest.unmock('@shell/composables/useI18n')combined withjest.resetModules()inbeforeEach— this bypasses the global mock and loads the real implementation fresh for each test.@shell/plugins/i18nis mocked per-test to isolate thestringFordependency.Tests Added (9 total)
useI18n(store)returns{ t }function'usI18n() must be called from setup()'stringFor(store, key, args, raw)undefinedfor args and rawstringForconsole.warncalled whenprocess.env.devis setconsole.warnnot called withoutprocess.env.devt()uses the most recently bound storeCoverage Impact
Before:
useI18n.ts— 0 dedicated testsAfter: All branches and paths covered (initialization guard, both
t()branches, dev-mode conditional)Reproducibility
Test Status
✅ All 9 tests pass
✅ ESLint passes with
--max-warnings 0Warning
Firewall blocked 1 domain
The following domain was blocked by the firewall during workflow execution:
download.cypress.ioSee Network Configuration for more information.