【发布时间】:2022-01-01 10:57:28
【问题描述】:
有没有办法测试页面在 next.js 中的呈现方式?
不是通过比较html,而是通过实际图像。
到目前为止,我只找到了一种使用toJSON() 将组件“渲染”为 html(标签树)的方法:
import React from 'react'
import TestRenderer from 'react-test-renderer'
import Index from './index'
it(`should render`, () => {
const testRenderer = TestRenderer.create(<Index/>)
expect(testRenderer.toJSON()).toMatchSnapshot()
})
但没有关于如何使用实际渲染和真实图像执行此操作的信息。
最后,我希望能够以像素完美的精度将当前图像与参考图像进行比较。 有可能吗?
【问题讨论】: