Unverified Commit 193d049d authored by Joe Haddad's avatar Joe Haddad Committed by GitHub

Test for <Document> fragment `styles` (#7875)

parent 8122d821
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
function Hi () {
return (
<div>
<p>Hello world!</p>
<style jsx>{`
p {
font-size: 16.4px;
}
`}</style>
</div>
)
}
Hi.getInitialProps = () => ({})
export default Hi
/* 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/)
})
})
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