Skip to content

Commit

Permalink
More tests
Browse files Browse the repository at this point in the history
  • Loading branch information
amannn committed Sep 17, 2024
1 parent dab7dae commit 7fe9907
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions packages/next-intl/src/middleware/utils.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -171,20 +171,34 @@ describe('getInternalTemplate', () => {
});

describe('getPathnameMatch', () => {
it('prioritizes more specific prefixes for overlapping locales', () => {
expect(
getPathnameMatch('/de/at/test', ['de', 'de-at'], {
mode: 'always',
prefixes: {
'de-at': '/de/at',
de: '/de'
}
})
).toEqual({
it('prioritizes more specific custom prefixes for overlapping ones', () => {
const locales = ['de', 'de-at', 'de-at-x-test'] as const;
const localePrefix = {
mode: 'always',
prefixes: {
de: '/de',
'de-at': '/de/at',
// Longer locale, shorter prefix
'de-at-x-test': '/de/a'
}
} as const;

expect(getPathnameMatch('/de/at/test', locales, localePrefix)).toEqual({
locale: 'de-at',
prefix: '/de/at',
exact: true,
matchedPrefix: '/de/at'
});
});

it('does not confuse unrelated parts of the pathname with a locale', () => {
expect(
getPathnameMatch('/de/ats', ['de', 'de-at'], {mode: 'always'})
).toEqual({
locale: 'de',
prefix: '/de',
exact: true,
matchedPrefix: '/de'
});
});
});

0 comments on commit 7fe9907

Please sign in to comment.