-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Closed
Labels
needs discussionWhether changes are needed is still undecided and additional discussion is needed.Whether changes are needed is still undecided and additional discussion is needed.
Description
Describe the feature you'd like:
Currently there is no documentation, recommendations or API's that I could find regarding testing components that are rendered in a server side context.
Suggested implementation:
Describe alternatives you've considered:
currently, I use the hack
/**
* @jest-environment node
*/
import React from 'react'
import { renderToString } from 'react-dom/server'
const foo = () => <img src="bar.png"/>
describe('Server-side rendering', () => {
it('renders on a server without crashing', () => {
const foo = () => <img src="bar.png"/>
const renderOnServer = () =>
renderToString(
<main>
<foo/>
</main>,
)
expect(renderOnServer).not.toThrow()
})
it('renders with the src attribute', () => {
const foo = () => <img src="bar.png"/>
const ElementImageHtml = renderToString(<foo/>)
expect(ElementImageHtml).toContain('src="bar.png"')
})
})
Metadata
Metadata
Assignees
Labels
needs discussionWhether changes are needed is still undecided and additional discussion is needed.Whether changes are needed is still undecided and additional discussion is needed.