Commit 92b0a690 authored by Arunoda Susiripala's avatar Arunoda Susiripala Committed by GitHub

Add a default value of '{}' to query in the export mode. (#2003)

parent a8fdbb26
...@@ -88,7 +88,7 @@ export default async function (dir, options) { ...@@ -88,7 +88,7 @@ export default async function (dir, options) {
for (const path of exportPaths) { for (const path of exportPaths) {
log(` exporting path: ${path}`) log(` exporting path: ${path}`)
const { page, query } = exportPathMap[path] const { page, query = {} } = exportPathMap[path]
const req = { url: path } const req = { url: path }
const res = {} const res = {}
......
...@@ -3,6 +3,7 @@ module.exports = { ...@@ -3,6 +3,7 @@ module.exports = {
return { return {
'/': { page: '/' }, '/': { page: '/' },
'/about': { page: '/about' }, '/about': { page: '/about' },
'/get-initial-props-with-no-query': { page: '/get-initial-props-with-no-query' },
'/counter': { page: '/counter' }, '/counter': { page: '/counter' },
'/dynamic-imports': { page: '/dynamic-imports' }, '/dynamic-imports': { page: '/dynamic-imports' },
'/dynamic': { page: '/dynamic', query: { text: 'cool dynamic text' } }, '/dynamic': { page: '/dynamic', query: { text: 'cool dynamic text' } },
......
const Page = ({ query }) => (
<div>
{ `Query is: ${query}` }
</div>
)
Page.getInitialProps = ({ query }) => {
return { query: JSON.stringify(query) }
}
export default Page
...@@ -22,5 +22,10 @@ export default function (context) { ...@@ -22,5 +22,10 @@ export default function (context) {
const html = await renderViaHTTP(context.port, '/dynamic-imports') const html = await renderViaHTTP(context.port, '/dynamic-imports')
expect(html).toMatch(/Welcome to dynamic imports./) expect(html).toMatch(/Welcome to dynamic imports./)
}) })
it('should give empty object for query if there is no query', async() => {
const html = await renderViaHTTP(context.port, '/get-initial-props-with-no-query')
expect(html).toMatch(/Query is: {}/)
})
}) })
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment