-
Notifications
You must be signed in to change notification settings - Fork 0
test: unify i18next mocks into centralized helpers #145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: qodo_action_req_1_base_test_unify_i18next_mocks_into_centralized_helpers_pr7
Are you sure you want to change the base?
Conversation
Consolidate scattered i18next mock implementations across test files into a single source of truth. This reduces duplication and ensures consistent mock behavior. - Create test/i18n-mock.ts with reusable factory functions - Update vitest.setup.ts to use the centralized helpers - Remove redundant mock definitions from 8 test files - Update testing.md documentation 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
…eateReactI18nextMock` and detail global mock provisions.
Code Review by Qodo
1. TranslationMap declared as interface
|
| import * as React from 'react' | ||
| import { vi } from 'vitest' | ||
|
|
||
| interface TranslationMap extends Record<string, string | string[]> {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1. translationmap declared as interface 📘 Rule violation ✓ Correctness
• web/test/i18n-mock.ts introduces interface TranslationMap ..., which violates the requirement to use type aliases instead of interface. • This will trigger the repo’s ts/consistent-type-definitions rule and can block CI/linting for TypeScript code.
Agent prompt
## Issue description
TypeScript lint rule requires `type` aliases instead of `interface`, but the new `web/test/i18n-mock.ts` defines `TranslationMap` as an `interface`.
## Issue Context
Repo enforces `ts/consistent-type-definitions` (per compliance ID 16).
## Fix Focus Areas
- web/test/i18n-mock.ts[4-4]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
| // mock react-i18next | ||
| vi.mock('react-i18next', async () => { | ||
| const actual = await vi.importActual<typeof import('react-i18next')>('react-i18next') | ||
| const { createReactI18nextMock } = await import('./test/i18n-mock') | ||
| return { | ||
| ...actual, | ||
| useTranslation: (defaultNs?: string) => ({ | ||
| t: (key: string, options?: Record<string, unknown>) => { | ||
| if (options?.returnObjects) | ||
| return [`${key}-feature-1`, `${key}-feature-2`] | ||
| const ns = options?.ns ?? defaultNs | ||
| if (options || ns) { | ||
| const { ns: _ns, ...rest } = options ?? {} | ||
| const prefix = ns ? `${ns}.` : '' | ||
| const suffix = Object.keys(rest).length > 0 ? `:${JSON.stringify(rest)}` : '' | ||
| return `${prefix}${key}${suffix}` | ||
| } | ||
| return key | ||
| }, | ||
| i18n: { | ||
| language: 'en', | ||
| changeLanguage: vi.fn(), | ||
| }, | ||
| }), | ||
| ...createReactI18nextMock(), | ||
| } | ||
| }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2. Returnobjects not mocked 🐞 Bug ✓ Correctness
• The new global react-i18next mock delegates to createReactI18nextMock(), whose t()
implementation never handles options.returnObjects.
• Components using t(..., { returnObjects: true }) as string[] and then iterating (e.g.
features.map(...)) will receive a string from the global mock, causing runtime errors in tests.
• This is a regression vs. prior global behavior and can surface as `TypeError: features.map is not
a function`.
Agent prompt
### Issue description
The new global i18n mock’s `t()` implementation does not handle `options.returnObjects`. Components that expect arrays from `t(..., { returnObjects: true })` can crash in tests when the global mock returns a string.
### Issue Context
Previously, the global mock explicitly handled `returnObjects`. After refactor, `web/vitest.setup.ts` uses `createReactI18nextMock()` which currently always returns a string fallback.
### Fix Focus Areas
- web/test/i18n-mock.ts[10-28]
- web/vitest.setup.ts[88-96]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
Benchmark PR from agentic-review-benchmarks#7