Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
amannn committed Dec 5, 2024
1 parent a5733c9 commit 101bb5e
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions packages/next-intl/src/middleware/middleware.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2704,6 +2704,27 @@ describe('domain-based routing', () => {
} satisfies Pathnames<ReadonlyArray<'en' | 'fr'>>
});

it('redirects an unprefixed pathname from the fr locale on the en domain', () => {
middlewareWithPathnames(
createMockRequest('/a-propos', 'fr', 'http://en.example.com')
);
expect(MockedNextResponse.redirect).toHaveBeenCalled();
expect(MockedNextResponse.redirect.mock.calls[0][0].toString()).toBe(
'http://en.example.com/about'
);
});

it('redirects a prefixed pathname from the fr locale on the en domain', () => {
middlewareWithPathnames(
createMockRequest('/fr/a-propos', 'fr', 'http://en.example.com')
);
expect(MockedNextResponse.redirect).toHaveBeenCalled();
expect(MockedNextResponse.redirect.mock.calls[0][0].toString()).toBe(
// (will get another redirect to /a-propos on this domain)
'http://fr.example.com/fr/a-propos'
);
});

it('serves requests for the default locale at the root', () => {
middlewareWithPathnames(
createMockRequest('/', 'en', 'http://en.example.com')
Expand Down

0 comments on commit 101bb5e

Please sign in to comment.