問題描述
我是單元測試的新手.我想測試 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和酶有什么區別?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!