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:
parent
af89e9ac30
commit
080bee6935
1 changed files with 30 additions and 0 deletions
30
packages/core/src/i18n/detect-language.test.ts
Normal file
30
packages/core/src/i18n/detect-language.test.ts
Normal 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);
|
||||
});
|
||||
});
|
Loading…
Add table
Reference in a new issue