[英]snapshot testing with react-test-renderer
I'm trying to create a test case for App component which has the following providers. 我正在尝试为具有以下提供程序的App组件创建测试用例。
I'm trying to render the app which certain state, to ensure the same app is rendered. 我正在尝试呈现某个特定状态的应用程序,以确保呈现相同的应用程序。 The test case passes, but I get the following as snapshot.
测试用例通过了,但是我得到了以下快照。
// Jest Snapshot v1, [link to jest docs]
exports[`This should Render App 1`] = `null`;
exports[`This should Render App 2`] = `null`;
My test case is like this, 我的测试用例是这样的,
const component = renderer.create(
<App store={store} persistor={persistor} />,
);
let tree = component.toJSON();
expect(tree).toMatchSnapshot();
tree
is not null and has the rendered component. tree
不为null,具有呈现的组件。 But I do not see this being written in snapshot. 但是我看不到它写在快照中。
npm package versions npm软件包版本
"jest": "^22.4.4",
"react-test-renderer": "^16.4.0",
I was able to fix the issue by using .toTree()
method available in react-test-renderer
instead of toJSON()
. 我能够通过使用
react-test-renderer
可用的.toTree()
方法而不是toJSON()
来解决此问题。
toMatchSnapshot()
of jest seems to accept only ReactTestRendererTree
as apposed to ReactTestRendererJSON
. toMatchSnapshot()
开玩笑的,似乎只接受ReactTestRendererTree
作为并列于ReactTestRendererJSON
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.