rsnext/test/unit/validate-url.test.ts
Jiachi Liu ef2b8f8696
Fix canonical url for dynamic routes (#49512)
The `pathname` in app-render was actually "page" (e.g. `/blog/[slug]`),
with special url conventions. Instead we should use actual request url
as pathname. Rename previous `pathname` arg to `pagePath` for better
readability

Also improved the url validation
2023-05-09 16:31:06 -07:00

13 lines
405 B
TypeScript

import { validateURL } from 'next/dist/server/app-render/validate-url'
describe('validateUrl', () => {
it('should return valid pathname', () => {
expect(validateURL('/')).toBe('/')
expect(validateURL('/abc')).toBe('/abc')
})
it('should throw for invalid pathname', () => {
expect(() => validateURL('//**y/\\')).toThrow()
expect(() => validateURL('//google.com')).toThrow()
})
})