mirror of
https://github.com/logto-io/logto.git
synced 2025-02-10 21:58:23 -05:00
28 lines
776 B
TypeScript
28 lines
776 B
TypeScript
|
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();
|
||
|
});
|
||
|
});
|