Jest和酶有什么区别?

What is the difference between Jest and enzyme?(Jest和酶有什么区别?)
本文介绍了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.

Jestenzyme有什么区别?

  • enzyme断言库还是任务运行器?
  • 我可以将 karmaJasmine 一起使用吗?
  • 测试 react-redux 项目的最佳方法是什么?
  • Is enzyme assertion library or task runner?
  • Can I use karma with Jasmine?
  • 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和酶有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Drag amp; Drop with Protractor by Repeater(拖动amp;通过中继器使用量角器掉落)
Getting the position of the element in a list when it#39;s drag/dropped (ui.sortable)(拖放时获取元素在列表中的位置(ui.sortable))
Detecting HTML5 Drag And Drop support in javascript(在 javascript 中检测 HTML5 拖放支持)
HTML5 drop event doesn#39;t work unless dragover is handled(除非处理了拖动,否则 HTML5 放置事件不起作用)
How to use jQuery#39;s drop event to upload files dragged from the desktop?(如何使用 jQuery 的 drop 事件上传从桌面拖动的文件?)
Drop image into contenteditable in Chrome to the cursor(将图像拖放到 Chrome 中的 contenteditable 到光标处)