jest快照测试:如何在jest测试结果中忽略部分快照文件 [英] jest snapshot testing: how to ignore part of the snapshot file in jest test results

查看:127
本文介绍了jest快照测试:如何在jest测试结果中忽略部分快照文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:忽略.snap文件测试结果的某些部分

Problem: ignore some part of the .snap file test results

这里的问题:我的测试中有一些组件具有随机值,我并不真的在乎测试它们.有什么办法可以忽略我的X.snap文件的一部分?因此,当我将来运行测试时,它不会给我测试失败的结果.

the question here: there are some components in my test that have a random values and i don't really care about testing them. is there any way to ignore part of my X.snap file? so when i run tests in the future it won't give me test fail results.

推荐答案

实际上,您需要模拟运动部件.

Actually, you need to mock the moving parts.

最好的文档:

您的测试应该是确定性的.也就是说,在未更改的组件上多次运行相同的测试应该每次都产生相同的结果.您有责任确保所生成的快照不包括特定于平台的数据或其他不确定的数据.

Your tests should be deterministic. That is, running the same tests multiple times on a component that has not changed should produce the same results every time. You're responsible for making sure your generated snapshots do not include platform specific or other non-deterministic data.

如果与时间有关,可以使用

If it's something related to time, you could use

Date.now = jest.fn(() => 1482363367071);

这篇关于jest快照测试:如何在jest测试结果中忽略部分快照文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆