@i18n-micro/test-utils

Testing helpers for Nuxt I18n Micro (translations, locales, formatting mocks).
152,219 251
Install
npm install @i18n-micro/test-utils
Latest Version:1.2.19
License:MIT
Last Updated:Oct 15, 2026
Links: GitHub  ·  npm
Maintainer: s00d

Nuxt I18n Micro Test Utils

Nuxt unit-test mocks for useI18n() — translations, locale state, and lightweight path stubs. Pair with @nuxt/test-utils + Vitest.

Features

  • setupNuxtI18nMock — one-call isolated harness + beforeEach reseed (keep mockNuxtImport in your setup file)
  • createFakeI18n / createIsolatedFakeI18n — useI18n()-shaped object ($t / t, helper, optional vi.fn spies)
  • Factory options — locales, translations, messages, strategy, …
  • resetI18n — clear the shared dictionary cache between tests
  • Translation helpers — t, tc, ts, mergeTranslations, resolveTranslations, setTranslation
  • Path stubs — localePath / switchLocalePath (prefix strategies; does not mutate locale)

Installation

npm install @i18n-micro/test-utils --save-dev

Quick setup

// tests/unit-setup.ts
import { setupNuxtI18nMock } from '@i18n-micro/test-utils'
import { mockNuxtImport } from '@nuxt/test-utils/runtime'
import { beforeEach, vi } from 'vitest'

const { i18n, useI18n, setTranslationsFromJson } = setupNuxtI18nMock({
  spy: vi.fn,
  beforeEach,
})

mockNuxtImport('useI18n', () => useI18n)

export { i18n, setTranslationsFromJson }

Load dictionaries in a test:

await setTranslationsFromJson('en', { welcome: 'Welcome' })
expect(i18n.$t('welcome')).toBe('Welcome')
expect(i18n.$localePath('/about')).toBe('/en/about')
expect(i18n.$switchLocalePath('de')).toBe('/de/about')
expect(i18n.$getLocale()).toBe('en') // switchLocalePath does not change locale

See the testing guide and the example/ Nuxt app.

License

MIT License. See the LICENSE file for details.

Author

Related Packages

nuxt-vitest-shared-app

Run Nuxt component tests in Vitest on one shared app per worker, with per-test c...

546 0
@vintl/nuxt

Nuxt Module for VIntl integration

9,922 2
@brc-dd/nuxt-i18n

Minimal module for i18n with locale auto-imports & localized routing

898 12
@nuxtjs/i18n

Internationalization for Nuxt

23,877,608 2,085
vitest-browser-vue

Render Vue components in Vitest Browser Mode

5,213,984 79

Version History

Version Released License
1.2.19 MIT
1.2.18 MIT
1.2.17 MIT
1.2.16 MIT
1.2.15 MIT