Closed
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"')
})
})