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和酶有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:Jest和酶有什么区别?

基础教程推荐