test: Add error on malformed URL (#5269)

This commit is contained in:
Matsumoto Toshi 2019-03-19 19:26:37 +09:00 committed by Xin Du (Clark)
parent d03a61b040
commit 8bbb269d80
1 changed files with 15 additions and 0 deletions

View File

@ -306,4 +306,19 @@ describe('server: nuxtMiddleware', () => {
expect(await nuxtMiddleware(req, res, next)).toBe(err)
expect(consola.error).toBeCalledWith(err)
})
test('should return 400 if request is uri error', async () => {
const context = createContext()
const result = { html: 'rendered html' }
context.renderRoute.mockReturnValue(result)
const nuxtMiddleware = createNuxtMiddleware(context)
const { req, res, next } = createServerContext()
const err = Error('URI malformed')
err.name = 'URIError'
await nuxtMiddleware({ ...req, url: 'http://localhost/test/server/%c1%81' }, res, next)
expect(next).toBeCalledWith(err)
})
})