JavaScript的世界日新月异,随着我们使用框架的经验越来越多,我们的倾向也在改变。我们深入使用某些框架,其他备选框架自然黯然失色。在React前端测试方面,React Testing Library就是这样一个例子。我们团队很喜欢的是,用这个框架写的测试比其他框架(如 Enzyme)更健壮,因为它鼓励独立测试组件间的关系,而不是测试全部实现细节。 这种思维源自于测试库,React Testing Library 是它的一部分,它还为像Angular 和 Vue.js这样的框架提供了一整套库。
JavaScript世界日新月异,随着我们在框架使用方面的经验越来越多,我们的推荐也随之改变。有些框架随着我们的深入使用,会使其他类似框架都黯然失色。在React前端测试方面,React Testing Library就是这样一个例子。用它写的测试比其他框架(如Enzyme)脆弱,因为它鼓励独立测试组件间的关系,而不是测试全部实现细节。
As the pace of change in JavaScript frameworks has slowed, our teams have more time to work with specific frameworks and are gaining deeper insights as a result. With React and the dominant testing framework, Enzyme, we've observed a worrying trend of unit tests becoming tightly coupled to implementation details without providing — because the focus is on shallow details — much confidence that features work as expected. These unit tests make evolving the design difficult and they shift too much responsibility up the test pyramid to functional testing. This has made us revisit the idea of subcutaneous testing. Additionally, because of its design, Enzyme has issues trying to keep up with React's development. All this has pushed us toward assessing react-testing-library as a new framework for testing React applications.