forked from github/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: detect-language correctly handles root path, add unit tests (git…
- Loading branch information
1 parent
6112336
commit bede852
Showing
2 changed files
with
25 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { expect } from '@jest/globals' | ||
import { getLanguageCodeFromPath } from '../../middleware/detect-language.js' | ||
|
||
describe('detect-language - getLanguageCodeFromPath', () => { | ||
test('should handle client-side routing path shape', () => { | ||
expect(getLanguageCodeFromPath('/_next/data/development/ja/articles/foo')).toBe('ja') | ||
}) | ||
|
||
test('should return for paths with an extension', () => { | ||
expect(getLanguageCodeFromPath('/ja.json')).toBe('ja') | ||
expect(getLanguageCodeFromPath('/_next/data/development/ja.json')).toBe('ja') | ||
}) | ||
|
||
test('should return en for invalid languages', () => { | ||
expect(getLanguageCodeFromPath('/xx/articles/foo')).toBe('en') | ||
expect(getLanguageCodeFromPath('/_next/data/development/xx/articles/foo')).toBe('en') | ||
}) | ||
}) |