Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
26a2f603
Unverified
Commit
26a2f603
authored
Jan 10, 2024
by
Wyatt Johnson
Committed by
GitHub
Jan 10, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Handle pages double render for useParams in tests (#60486)
Closes NEXT-2048
parent
3c065a1f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
26 deletions
+44
-26
navigation.test.ts
test/e2e/app-dir/navigation/navigation.test.ts
+44
-26
No files found.
test/e2e/app-dir/navigation/navigation.test.ts
View file @
26a2f603
import
{
createNextDescribe
}
from
'e2e-utils'
import
{
createNextDescribe
}
from
'e2e-utils'
import
{
check
,
waitFor
}
from
'next-test-utils'
import
{
check
,
retry
,
waitFor
}
from
'next-test-utils'
import
type
{
Request
}
from
'playwright-chromium'
import
type
{
Request
}
from
'playwright-chromium'
createNextDescribe
(
createNextDescribe
(
...
@@ -67,50 +67,68 @@ createNextDescribe(
...
@@ -67,50 +67,68 @@ createNextDescribe(
})
})
describe
(
'useParams identity between renders'
,
()
=>
{
describe
(
'useParams identity between renders'
,
()
=>
{
async
function
runTests
(
page
:
string
)
{
async
function
runTests
(
page
:
string
,
waitForNEffects
:
number
)
{
const
browser
=
await
next
.
browser
(
page
)
const
browser
=
await
next
.
browser
(
page
)
await
check
(
// Expect to see the params changed message at least twice.
async
()
=>
JSON
.
stringify
(
await
browser
.
log
()),
let
lastLogIndex
=
await
retry
(
async
()
=>
{
/params changed/
const
logs
:
Array
<
{
message
:
string
}
>
=
await
browser
.
log
()
)
let
outputIndex
=
(
await
browser
.
log
()).
length
expect
(
logs
.
filter
(({
message
})
=>
message
===
'params changed'
)
).
toHaveLength
(
waitForNEffects
)
return
logs
.
length
})
await
browser
.
elementById
(
'rerender-button'
).
click
()
await
browser
.
elementById
(
'rerender-button'
).
click
()
await
browser
.
elementById
(
'rerender-button'
).
click
()
await
browser
.
elementById
(
'rerender-button'
).
click
()
await
browser
.
elementById
(
'rerender-button'
).
click
()
await
browser
.
elementById
(
'rerender-button'
).
click
()
await
check
(
async
()
=>
{
await
retry
(
async
()
=>
{
return
browser
.
elementById
(
'rerender-button'
).
text
()
const
rerender
=
await
browser
.
elementById
(
'rerender-button'
).
text
()
},
'Re-Render 3'
)
await
check
(
async
()
=>
{
expect
(
rerender
).
toBe
(
'Re-Render 3'
)
const
logs
=
await
browser
.
log
()
})
return
JSON
.
stringify
(
logs
.
slice
(
outputIndex
)).
includes
(
'params changed'
let
logs
:
Array
<
{
message
:
string
}
>
=
await
browser
.
log
()
)
expect
(
logs
.
slice
(
lastLogIndex
)).
not
.
toContainEqual
(
?
'fail'
expect
.
objectContaining
({
:
'success'
message
:
'params changed'
,
},
'success'
)
})
)
outputIndex
=
(
await
browser
.
log
())
.
length
lastLogIndex
=
logs
.
length
await
browser
.
elementById
(
'change-params-button'
).
click
()
await
browser
.
elementById
(
'change-params-button'
).
click
()
await
check
(
await
retry
(
async
()
=>
{
async
()
=>
logs
=
await
browser
.
log
()
JSON
.
stringify
((
await
browser
.
log
()).
slice
(
outputIndex
)),
/params changed/
expect
(
logs
.
slice
(
lastLogIndex
)).
toContainEqual
(
)
expect
.
objectContaining
({
message
:
'params changed'
,
})
)
})
}
}
it
(
'should be stable in app'
,
async
()
=>
{
it
(
'should be stable in app'
,
async
()
=>
{
await
runTests
(
'/search-params/foo'
)
await
runTests
(
'/search-params/foo'
,
// App Router doesn't re-render on initial load (the params are baked
// server side). In development, effects will render twice.
isNextDev
?
2
:
1
)
})
})
it
(
'should be stable in pages'
,
async
()
=>
{
it
(
'should be stable in pages'
,
async
()
=>
{
await
runTests
(
'/search-params-pages/foo'
)
await
runTests
(
'/search-params-pages/foo'
,
// Pages Router re-renders on initial load and after hydration, the
// params when initially loaded are null.
2
)
})
})
})
})
})
})
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment