UNPKG

ember-intl

Version:

Internationalization for Ember projects

37 lines (31 loc) 1.03 kB
import { getContext, settled, type TestContext } from '@ember/test-helpers'; import type { Translations } from 'ember-intl/-private/utils/translations'; import { onMissingTranslation } from './-private/on-missing-translation'; import { addTranslations } from './add-translations'; /** * In addition to the `hooks` object, you must specify the locale * under which your tests make sense. * * You may pass a `translations` object to stub the translations. * * @param {object} hooks * @param {string} locale * @param {object} [translations] */ export function setupIntl( hooks: NestedHooks, locale: string, translations?: Translations, ): void { hooks.beforeEach(async function (this: TestContext) { const { owner } = getContext() as TestContext; const intl = owner.lookup('service:intl'); intl.setLocale(locale); intl.setOnMissingTranslation(onMissingTranslation); if (translations) { await addTranslations(locale, translations); } else { await settled(); } }); }