File tree Expand file tree Collapse file tree 6 files changed +24
-10
lines changed Expand file tree Collapse file tree 6 files changed +24
-10
lines changed Original file line number Diff line number Diff line change @@ -29,6 +29,7 @@ module.exports = phase => {
2929 query : { text : 'this file has an extension' } ,
3030 } ,
3131 '/query' : { page : '/query' , query : { a : 'blue' } } ,
32+ '/query-update' : { page : '/query-update' , query : { a : 'blue' } } ,
3233 // API route
3334 '/blog/nextjs/comment/test' : { page : '/blog/[post]/comment/[id]' } ,
3435 }
Original file line number Diff line number Diff line change 1+ import { useRouter } from 'next/router'
2+
3+ const Page = ( ) => < div id = "query" > { JSON . stringify ( useRouter ( ) . query ) } </ div >
4+
5+ Page . getInitialProps = ( ) => ( { hello : 'world' } )
6+
7+ export default Page
Original file line number Diff line number Diff line change @@ -183,11 +183,10 @@ export default function(context) {
183183 } )
184184
185185 it ( 'should update query after mount' , async ( ) => {
186- const browser = await webdriver ( context . port , '/query?hello=1' )
187-
188- await waitFor ( 1000 )
189- const text = await browser . eval ( 'document.body.innerHTML' )
190- expect ( text ) . toMatch ( / h e l l o / )
186+ const browser = await webdriver ( context . port , '/query-update?hello=world' )
187+ await waitFor ( 2000 )
188+ const query = await browser . elementByCss ( '#query' ) . text ( )
189+ expect ( JSON . parse ( query ) ) . toEqual ( { hello : 'world' , a : 'blue' } )
191190 await browser . close ( )
192191 } )
193192
Original file line number Diff line number Diff line change @@ -34,6 +34,7 @@ module.exports = phase => {
3434 query : { text : 'this file has an extension' } ,
3535 } ,
3636 '/query' : { page : '/query' , query : { a : 'blue' } } ,
37+ '/query-update' : { page : '/query-update' , query : { a : 'blue' } } ,
3738 // API route
3839 '/blog/nextjs/comment/test' : { page : '/blog/[post]/comment/[id]' } ,
3940 }
Original file line number Diff line number Diff line change 1+ import { useRouter } from 'next/router'
2+
3+ const Page = ( ) => < div id = "query" > { JSON . stringify ( useRouter ( ) . query ) } </ div >
4+
5+ Page . getInitialProps = ( ) => ( { hello : 'world' } )
6+
7+ export default Page
Original file line number Diff line number Diff line change @@ -183,11 +183,10 @@ export default function(context) {
183183 } )
184184
185185 it ( 'should update query after mount' , async ( ) => {
186- const browser = await webdriver ( context . port , '/query?hello=1' )
187-
188- await waitFor ( 1000 )
189- const text = await browser . eval ( 'document.body.innerHTML' )
190- expect ( text ) . toMatch ( / h e l l o / )
186+ const browser = await webdriver ( context . port , '/query-update?hello=world' )
187+ await waitFor ( 2000 )
188+ const query = await browser . elementByCss ( '#query' ) . text ( )
189+ expect ( JSON . parse ( query ) ) . toEqual ( { hello : 'world' , a : 'blue' } )
191190 await browser . close ( )
192191 } )
193192
You can’t perform that action at this time.
0 commit comments