Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save nonnullish/23f77ea632824f154498c0c21c8bfde6 to your computer and use it in GitHub Desktop.
Save nonnullish/23f77ea632824f154498c0c21c8bfde6 to your computer and use it in GitHub Desktop.
Mocking { t } from i18next in Jest unit tests

service.ts

import { t } from 'i18next';

export const myFunction = () => t('label.myLabel');

service.spec.ts

jest.mock('i18next', () => ({
  t: (label: string) => ({ 'labels.myLabel': 'My Label' }[label]),
}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment