rsnext/test/unit/image-rendering.unit.test.js
Steven 5562daf7a1
Fallback to default config to enable testing Image component (#19107)
Fixes #18415 by using the default config as fallback.

Users who wish to use their `next.config.js` values will still need the workaround from https://github.com/vercel/next.js/issues/18415#issuecomment-718180659
2020-11-12 19:24:08 +00:00

23 lines
717 B
JavaScript

/* eslint-env jest */
import React from 'react'
import ReactDOM from 'react-dom/server'
import Image from 'next/image'
import cheerio from 'cheerio'
describe('Image rendering', () => {
it('should render Image on its own', async () => {
const element = React.createElement(Image, {
id: 'unit-image',
src: '/test.png',
width: 100,
height: 100,
loading: 'eager',
})
const html = ReactDOM.renderToString(element)
const $ = cheerio.load(html)
const img = $('#unit-image')
expect(img.attr('id')).toBe('unit-image')
expect(img.attr('src')).toContain('/_next/image?url=%2Ftest.png')
expect(img.attr('srcset')).toContain('/_next/image?url=%2Ftest.png')
})
})