0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-02-10 21:58:23 -05:00
logto/packages/core/src/middleware/koa-i18next.test.ts

28 lines
776 B
TypeScript
Raw Normal View History

import i18next from 'i18next';
import initI18n from '@/i18n/init';
import { createContextWithRouteParamters } from '@/utils/test-utils';
import koaI18next from './koa-i18next';
// Can not access outter scope function in jest mock
// eslint-disable-next-line unicorn/consistent-function-scoping
jest.mock('@/i18n/detect-language', () => () => ['zh-cn']);
const changLanguageSpy = jest.spyOn(i18next, 'changeLanguage');
describe('koaI18next', () => {
const next = jest.fn();
it('deteact language', async () => {
const ctx = {
...createContextWithRouteParamters(),
query: {},
locale: 'en',
};
await initI18n();
await koaI18next()(ctx, next);
expect(ctx.locale).toEqual('zh-CN');
expect(changLanguageSpy).toBeCalled();
});
});