是否可以将反应测试库与故事书故事镜头插件一起使用?我想对不使用酶的反应成分进行一些测试。
对你来说可能有点晚了,但我只是在研究这个确切的问题。这是我想出的配置,它似乎对我有用。
import initStoryshots from "@storybook/addon-storyshots";
import path from "path";
import { render } from "react-testing-library";
const reactTestingLibrarySerializer = {
print: (val, serialize, indent) => serialize(val.container.firstChild),
test: (val) => val && val.hasOwnProperty("container")
};
initStoryshots({
configPath: path.join(__dirname, "..", "config", "storybook"),
framework: "react",
integrityOptions: { cwd: path.join(__dirname, "stories") },
renderer: render,
snapshotSerializers: [reactTestingLibrarySerializer],
storyKindRegex: /^((?!.*?DontTest).)*$/
});
秘密是传递一个自定义的 Jest串行器 https://jestjs.io/docs/en/configuration#snapshotserializers-array-string为了快照序列化器 https://github.com/storybooks/storybook/tree/master/addons/storyshots/storyshots-core#snapshotserializers从渲染函数的结果获取容器并传递其firstChild进行序列化的选项。
如果需要,您可以在序列化之前修改容器的内容,以使用 DOM api 删除不稳定的属性或整个元素。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)