开玩笑不是为快照创建文件,而是将其嵌入到测试文件中
我正在尝试用嘲笑编写React JS应用的测试 当我编写快照测试时,开玩笑不会为快照创建文件,它将其嵌入到了这样的测试文件中,
test("it matches snapshot",()=>{
const tree = renderer
.create(<Button lable="click me"></Button>)
.toJSON();
expect(tree).toMatchInlineSnapshot(`
<div
className="button-style"
data-testid="button"
>
click me
</div>
`);
});
如何创建快照文件
I'm trying to write tests for a react js app with jest
when I write a snapshot test jest does not create files for snapshots it adds it inline to the testing file like this
test("it matches snapshot",()=>{
const tree = renderer
.create(<Button lable="click me"></Button>)
.toJSON();
expect(tree).toMatchInlineSnapshot(`
<div
className="button-style"
data-testid="button"
>
click me
</div>
`);
});
how to create a snapshot file
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可能,您现在已经知道这是因为您调用
tomatchinLinesNapshot
。该方法将快照的内容直接写入测试文件: htttps:htttps:// jestjs。 io/doc/快照测试#inline-snapshots 。要将快照保存到单独的文件中,您需要调用tomatchsnapshot
。Probably, you already know by now that it's because you call
toMatchInlineSnapshot
. This method writes the content of the snapshot directly into the test file: https://jestjs.io/docs/snapshot-testing#inline-snapshots. To save a snapshot into a separate file you need to calltoMatchSnapshot
instead.