开玩笑不是为快照创建文件,而是将其嵌入到测试文件中

发布于 2025-01-27 20:56:18 字数 367 浏览 2 评论 0原文

我正在尝试用嘲笑编写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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

哆啦不做梦 2025-02-03 20:56:18

可能,您现在已经知道这是因为您调用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 call toMatchSnapshot instead.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文