在每个套件或测试之后,Jest都会重置JSDOM文档吗? [英] Does Jest reset the JSDOM document after every suite or test?

查看:119
本文介绍了在每个套件或测试之后,Jest都会重置JSDOM文档吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在测试几个在安装和卸载时会到达其DOM结构外部的组件,以提供其他方式无法实现的特定交互功能.

I'm testing a couple of components that reach outside of their DOM structure when mounting and unmounting to provide specific interaction capability that wouldn't be possible otherwise.

我正在使用Jest和默认的JSDOM初始化在节点内创建类似浏览器的环境.我在文档中找不到任何建议建议Jest在每次测试执行后重置JSDOM的信息,如果不是这种情况,没有明确的文档说明如何手动执行此操作.

I'm using Jest and the default JSDOM initialization to create a browser-like environment within node. I couldn't find anything in the documentation to suggest that Jest reset JSDOM after every test execution, and there's no explicit documentation on how to do that manually if that is not the case.

我的问题是,Jest是在每个测试,套件之后重置JSDOM实例,还是在所有测试运行中都保留一个JSDOM实例?如果是这样,我该如何控制它?

My question is, does Jest reset the JSDOM instance after every test, suite or does it keep a single instance of JSDOM across all test runs? If so, how can I control it?

推荐答案

所有玩笑的测试文件都在其自己的线程中运行,因此它们之间没有任何共享,因此,您无需在测试运行后重置模拟或间谍.在笑话"页面中:

All jest test files run in its own thread, so nothing is shared between them, thats why you never need to reset mocks or spies after a test run. From the Jest page:

Jest使工作人员之间的测试运行并行化,以最大化性能. 控制台消息被缓冲并与测试结果一起打印. 沙盒测试文件,并为每个测试自动重置全局状态 因此没有两个测试会相互冲突.

Jest parallelizes test runs across workers to maximize performance. Console messages are buffered and printed together with test results. Sandboxed test files and automatic global state resets for every test so no two tests conflict with each other.

这篇关于在每个套件或测试之后,Jest都会重置JSDOM文档吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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