0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-01-27 21:39:16 -05:00

test(i18n): add detectLanguage util test (#231)

add detectLanguage util test
This commit is contained in:
simeng-li 2022-02-16 10:26:16 +08:00 committed by GitHub
parent af89e9ac30
commit 080bee6935
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -0,0 +1,30 @@
import { createMockContext } from '@shopify/jest-koa-mocks';
import { ParameterizedContext } from 'koa';
import detectLanguage from './detect-language';
describe('detectLanguage', () => {
it('detectLanguage with request header', () => {
const ctx: ParameterizedContext<any, any, any> = createMockContext({
headers: {
'accept-language': 'en,en-US;q=0.9',
},
});
const language = detectLanguage(ctx);
expect(language).toEqual(['en', 'en-US']);
});
it('return empty if non-language is detected', () => {
const ctx: ParameterizedContext<any, any, any> = createMockContext({
headers: {
'accept-language': '; q=0.9',
},
});
const language = detectLanguage(ctx);
expect(language.length).toEqual(0);
});
});