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
193d049d
Unverified
Commit
193d049d
authored
Jul 10, 2019
by
Joe Haddad
Committed by
GitHub
Jul 10, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Test for <Document> fragment `styles` (#7875)
parent
8122d821
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
93 additions
and
0 deletions
+93
-0
_document.js
...ntegration/app-document-style-fragment/pages/_document.js
+36
-0
index.js
test/integration/app-document-style-fragment/pages/index.js
+16
-0
index.test.js
...ntegration/app-document-style-fragment/test/index.test.js
+41
-0
No files found.
test/integration/app-document-style-fragment/pages/_document.js
0 → 100644
View file @
193d049d
import
Document
,
{
Html
,
Head
,
Main
,
NextScript
}
from
'next/document'
class
MyDocument
extends
Document
{
static
async
getInitialProps
(
ctx
)
{
const
initialProps
=
await
Document
.
getInitialProps
(
ctx
)
return
{
...
initialProps
,
styles
:
(
<>
{
initialProps
.
styles
}
<
style
id
=
'sbg'
dangerouslySetInnerHTML
=
{{
__html
:
`html { background: hotpink; }`
}}
/
>
<
/
>
)
}
}
render
()
{
return
(
<
Html
>
<
Head
/>
<
body
>
<
Main
/>
<
NextScript
/>
<
/body
>
<
/Html
>
)
}
}
export
default
MyDocument
test/integration/app-document-style-fragment/pages/index.js
0 → 100644
View file @
193d049d
function
Hi
()
{
return
(
<
div
>
<
p
>
Hello
world
!<
/p
>
<
style
jsx
>
{
`
p {
font-size: 16.4px;
}
`
}
<
/style
>
<
/div
>
)
}
Hi
.
getInitialProps
=
()
=>
({})
export
default
Hi
test/integration/app-document-style-fragment/test/index.test.js
0 → 100644
View file @
193d049d
/* eslint-env jest */
/* global jasmine */
import
{
join
}
from
'path'
import
cheerio
from
'cheerio'
import
{
stopApp
,
startApp
,
nextBuild
,
nextServer
,
renderViaHTTP
}
from
'next-test-utils'
jasmine
.
DEFAULT_TIMEOUT_INTERVAL
=
1000
*
60
const
appDir
=
join
(
__dirname
,
'../'
)
let
appPort
let
server
let
app
describe
(
'Custom Document Fragment Styles'
,
()
=>
{
beforeAll
(
async
()
=>
{
await
nextBuild
(
appDir
)
app
=
nextServer
({
dir
:
join
(
__dirname
,
'../'
),
dev
:
false
,
quiet
:
true
})
server
=
await
startApp
(
app
)
appPort
=
server
.
address
().
port
})
afterAll
(()
=>
stopApp
(
server
))
it
(
'correctly adds styles from fragment styles key'
,
async
()
=>
{
const
html
=
await
renderViaHTTP
(
appPort
,
'/'
)
const
$
=
cheerio
.
load
(
html
)
const
styles
=
$
(
'style'
).
text
()
expect
(
styles
).
toMatch
(
/background:
(
.*|
)
hotpink/
)
expect
(
styles
).
toMatch
(
/font-size:
(
.*|
)
16
\.
4px/
)
})
})
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