What is the difference between Jest and enzyme?(Jest和酶有什么区别?)
问题描述
我是单元测试的新手.我想测试 React 项目.当我开始使用 React 文档时,将酶称为测试实用程序,这对我来说有点模棱两可.
I'm new to Unit testing. I want to test React project. As I started with React documentation which refers to enzyme as test utility which is kind of ambiguous to me.
Jest
和enzyme
有什么区别?
- 是
enzyme
断言库还是任务运行器? - 我可以将
karma
与Jasmine
一起使用吗? - 测试
react-redux
项目的最佳方法是什么?
- Is
enzyme
assertion library or task runner? - Can I use
karma
withJasmine
? - What is the best way to test a
react-redux
project?
推荐答案
Jest 是一个包含任务运行器、断言库和模拟支持的框架.这意味着它可以执行不同的单元测试用例,将其结果写入控制台或日志文件,创建模拟或验证所有断言.简而言之,它将执行测试.
Jest is a framework which includes a task runner, assertion library, and mocking support. This means it can execute different unit test cases, write its result in console or log files, create mocks, or verify all the assertions. In short, it will execute the test.
Enzyme 是一个为编写单元测试提供简单接口的库.为此,它封装了 React TestUtils、JSDOM 和 CheerIO 等包.React TestUtils 具有将 React 组件渲染到文档中并模拟事件的方法.JSDOM 是 DOM(文档对象模型)的 JavaScript 实现.DOM 表示 UI 组件的树结构.CheerIO 实现了 jQuery 核心的一个子集,用于查询 DOM.
Enzyme, on other hand, is a library that provides a simple interface for writing unit tests. For this purpose, it wraps packages such as React TestUtils, JSDOM and CheerIO. React TestUtils has methods to render a React component into a document and to simulate an event. JSDOM is a JavaScript implementation of the DOM (Document object model). The DOM represents the tree structure of UI components. CheerIO implements a subset of jQuery core and is used to query the DOM.
Enzyme 不是测试运行器.它没有自己的断言库.它只是提供了一组用于单元测试的 API.这就是它可以与 Jest 或任何其他任务运行程序集成的原因.
Enzyme is not a test runner. It doesn't have its own assertion library. It just provides a collection of APIs for unit testing. That's why it could be integrated with Jest or any other task runner.
是的,你可以在茉莉花上使用因果报应.
Yes, you can use karma with jasmine.
这篇关于Jest和酶有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Jest和酶有什么区别?


- 是否可以将标志传递给 Gulp 以使其以不同的方式 2022-01-01
- 我不能使用 json 使用 react 向我的 web api 发出 Post 请求 2022-01-01
- 如何向 ipc 渲染器发送添加回调 2022-01-01
- 如何调试 CSS/Javascript 悬停问题 2022-01-01
- 为什么悬停在委托事件处理程序中不起作用? 2022-01-01
- 如何显示带有换行符的文本标签? 2022-01-01
- 使用 iframe URL 的 jQuery UI 对话框 2022-01-01
- 从原点悬停时触发 translateY() 2022-01-01
- 在不使用循环的情况下查找数字数组中的一项 2022-01-01
- 为什么我的页面无法在 Github 上加载? 2022-01-01