Skip to content

mockLocalize

Jason Godesky edited this page Jul 17, 2026 · 3 revisions

mockLocalize mocks Foundry’s game.i18n.localize utility method so that you can test code that uses it.

Parameters

translations: Record<string, string>

The dictionary of localizations that you would like the mock to use.

Examples

import { beforeEach, afterEach, describe, expect, it, vi } from 'vitest'
import { mockLocalize } from '@revolutionarygamesco/common-foundryvtt/mocks'

describe('Localization', () => {
  beforeEach(() => {
    mockLocalize({
      'TestModule.examples.mockLocalize': 'This is just an example'
    })
  })

  afterEach(() => {
    vi.unstubAllGlobals()
  })

  it('localizes the string', () => {
    expect(game.i18n.localize('TestModule.examples.mockLocalize')).toBe('This is just an example')
  })
})

Clone this wiki locally