|
所在平台: Udemy |
课程主页: https://www.udemy.com/course/react-testing-with-jest-and-enzyme/
课程评论:没有评论
**课程概述:React 测试进阶:Jest 与 Enzyme 实战(附重要声明)** 本课程旨在帮助您通过测试驱动开发(TDD)与 Jest 和 Enzyme 框架,提升您的 React 代码质量。Jest 作为一款强大的测试框架,结合 Enzyme(用于测试 React 和 Redux 应用),将帮助您掌握以下核心测试技能: * **React Hooks 测试:** 深入理解 `useEffect`、`useState` 和 `useReducer` 等 Hooks 的测试方法。 * **异步函数测试:** 使用 Axios 等工具测试异步操作。 * **Redux 核心测试:** 学习如何测试 Redux 的 action creators 和 reducers。 * **复杂 Redux 逻辑:** 掌握使用 Redux Thunk 处理复杂 action creators 的技巧。 * **React Context 测试:** 包括带状态的 Context 的测试方法。 * **Jest 高级特性:** * 模块属性的 Mocking 与恢复。 * Mocking 整个模块。 * 使用 `.skip` 和 `.only` 控制测试运行。 * 使用 `.each` 实现不同数据下的多轮测试。 **重要声明:** **Enzyme 已不再积极维护,且与 React 18 不兼容。** 对于计划学习新 React 应用测试或进行遗留项目迁移的学习者,**强烈建议优先选择 React Testing Library 课程**。本课程仅推荐给在遗留项目上工作、需要理解现有 Enzyme 测试,或有特定需求学习 Enzyme 的学员。 **为何学习测试?** TDD 有助于编写组织良好、易于维护的代码,长期来看可节省时间。测试可提升团队协作效率,让代码更可靠。测试技能是现代开发者的必备技能。 **测试类型:** 本课程侧重于**单元测试**,通过与代码紧密耦合,易于定位失败原因,非常适合 TDD。同时也会涉及**功能测试**,模拟用户流程,从用户角度验证行为,尽管与代码解耦,对代码重构更具韧性。 **深入理解测试逻辑:** 课程将探讨不同的测试方法及其权衡,帮助您建立对测试选择的信心。通过深入分析测试过程,您将加深对 React、Redux 和 Context 的理解。 **实践与巩固:** 课程提供实践机会,包括随项目进行的“小测验”和两套挑战题,并提供 GitHub 解决方案,帮助您巩固所学知识。 **关于 Enzyme 和 React 18 的重要更新(课程作者观点):** Enzyme 曾经是 React 测试的主流选择,但随着 React 版本的更新,其兼容性问题逐渐凸显。React 18 的发布以及 Enzyme 社区中关于 React 18 adapter 的不确定性,使得 Enzyme 的未来前景不明朗。作者本人不再推荐以 Enzyme 作为新项目的首选测试方案,并建议学习 React Testing Library,后者拥有更好的 React 版本兼容性和更简洁的使用体验。 **课程总结:** 本课程曾经是学习 React 测试的优质资源,但鉴于 Enzyme 的现状,作者不再力荐。如果您正在处理遗留项目或有特定需求,本课程仍可提供宝贵的 Enzyme 测试知识。然而,对于崭新的学习者,**React Testing Library 是更具前瞻性的选择**。
Please read the first lecture (reproduced at the end of this course description) before deciding to purchase this course. In short, Enzyme is no longer actively supported. Unless you're interested in learning Enzyme specifically (because you're working on a legacy React project that uses Enzyme tests), I recommend taking a React Testing Library course instead.**************************************************************************************************************Take your React code to the next level by learning Test Driven Development (TDD) with Jest and Enzyme! Jest is a powerful, flexible testing framework, and Enzyme provides tools to test React and Redux applications. In this course, you will learn to test:React hooks, including useEffect, useState and useReducerAsynchronous functions using AxiosRedux action creators and reducersComplex Redux action creators that use Redux ThunkReact context, including context with embedded stateYou will also learn how to make the most of Jest capabilities, includingMocking and restoring individual properties of modulesMocking entire modulesControlling which tests run using,.skip, and.onlyRunning test suites multiple times with different data, using.eachPlease Note: This course does not cover Jest snapshots, as they are not compatible with the TDD mode of testing.Why Learn to Test?Test Driven Development will help you write better organized code that's easier to maintain, which will save you time in the long run. Your tests provide value to your software development team, since others know they can rely on your code. Employers want developers with testing skills!Unit tests and Functional TestsThis course focuses on unit tests. Unit tests are tightly coupled to specific areas of code, which leads to easy diagnosis of failures, and a great match for Test-Driven Development. The course also teaches functional tests, which are modeled on user flows (and resulting behavior from the user perspective). Functional tests are not connected to code, which makes them more difficult to diagnose, but more resilient to code refactors.Learn the Reasons behind the SyntaxThis course discusses tradeoffs when considering different approaches to testing, leaving you confident in the testing choices you make. Furthermore, you will deepen your understanding of React, Redux and Context as we dig into how and why we test each aspect.Practice your New SkillsYou will also have opportunities to practice what you've learned. There are occasional "quizzes" while we're building the course projects, where you can apply what you learned, and then watch a video to see the solution. There are also two sets of challenges to extend the course projects, with solutions on GitHub.****************************************************************************************************************************************************************************************************************************This lecture/article is reproduced here, since Udemy articles do not preview well. Unfortunately, you will not get the full experience, as links are not available in the course description. First lecture / article: The Author's Thoughts on Enzyme and React 18The stark reality: Enzyme is not compatible with React 18, and probably never will be. The HistoryI started writing this course in March 2018, and it was published in May 2018. At that time, Enzyme was the primary option for testing React components with Jest. React Testing Library (Enzyme's current prime competitor) had just been released in March 2018.Since that time, a few things have happened: In June 2020, Enzyme switched from being maintained by Airbnb to being maintained by an individual. In October 2020, React 17 was released.Also in October 2020, an unofficial Enzyme adapter for React 17 was released.In December 2021, the author of the unofficial adapter for React 17 wrote an article entitled Enzyme is Dead, where he stated that he would not be writing an adapter for React 18.In March 2022, React 18 was released. In April 2022, the Enzyme maintainer has stated that he will work on a React 17 adapter before a React 18 adapter. As of April 2022, the official adapter for React 17 has not been released. Why I currently recommend React Testing LibraryReact Testing Library and Enzyme do the same job: rendering components so that they can be tested with Jest. I recommend React Testing Library over Enzyme for these reasons:Unlike Enzyme, React Testing Library does not rely on React internals. This means React Testing Library does not have an adapter that needs to be updated with each release of React, and is far less likely to have issues with new React versions. I find React Testing Library to be easier to use than Enzyme.What all this means for this courseNow that React 18 has come out and there's no React 17 adapter in sight, I don't believe there's a future for Enzyme. I would not recommend this course for people who are looking to learn how to test new React applications. Instead I would recommend you find a course on React Testing Library. That said, there are still around 2.4 million downloads of Enzyme a week (as of April 2022). Here are the circumstances under which I would recommend learning Enzyme: You are working on a legacy project that already has a large suite of Enzyme tests, and the project never intends to upgrade to React 18. You are working on a project with a large suite of existing Enzyme tests, and you wish to understand these tests before migrating to React Testing Library (RTL). However, Wojciech Maj, the author of the unoffiical Enzyme adapter for React 17, suggests: While Migrate from Enzyme support article is available, I suggest you to just start fresh, forgetting that Enzyme has ever existed. RTL is by no means an Enzyme drop-in replacement, so having a completely fresh mindset will help you getting the most of it.The Bottom LineEnzyme was a great way to test React applications when this course came out; however, I can no longer recommend it. I encourage you to study React Testing Library instead.