Setting up a shallow renderer for each test can be redundant, especially when trying to write similar tests that have slight tweaks. In this lesson, we go over how you can reduce some of the overlapping code so that each test only contains the unique pieces of the test.

describe('active class', ()=>{

    function renderLikeCounter(isActive){
const renderer = TestUtils.createRenderer();
renderer.render(<LikeCounter count={5} isActive={isActive}/>);
return renderer.getRenderOutput().props.className.includes('LikeCounter--active');
} it('should have active class based on isActive props: true', ()=>{
expect(renderLikeCounter(true)).toEqual(true);
}); it('should have active class based on isActive props: false', ()=>{
expect(renderLikeCounter(false)).toEqual(false);
});
});

[React Testing] Reusing test boilerplate的更多相关文章

  1. 如何使用TDD和React Testing Library构建健壮的React应用程序

    如何使用TDD和React Testing Library构建健壮的React应用程序 当我开始学习React时,我努力的一件事就是以一种既有用又直观的方式来测试我的web应用程序. 每次我想测试它时 ...

  2. React Testing All in One

    React Testing All in One React 测试 https://reactjs.org/docs/testing.html jest 26.4 https://jestjs.io/ ...

  3. [React Testing] Children with Shallow Rendering

    When testing React components, we often want to make sure the rendered output of the component match ...

  4. [React Testing] JSX error diffs -- expect-jsx library

    When writing React component tests, it can be hard to decipher the error diffs of broken tests, sinc ...

  5. [React Testing] Intro to Shallow Rendering

    In this lesson, we walk through how to use one of React's Test Utilities (from thereact-addons-test- ...

  6. [React Testing] Setting up dependencies && Running tests

    To write tests for our React code, we need to first install some libraries for running tests and wri ...

  7. [React & Testing] Simulate Event testing

    Here we want to test a toggle button component, when the button was click, state should change, styl ...

  8. [React & Testing] Snapshot testings

    For example we have a React comonent: -- A toggle button, we want to test. When it si toggle on, the ...

  9. [React Testing] The Redux Store - Multiple Actions

    When using Redux, we can test that our application state changes are working by testing that dispatc ...

随机推荐

  1. 使用linux操作系统的公司服务器有哪些品牌

    服务器硬件是什么牌子的? 操心系统有哪些?cpu是哪些?

  2. 富文本编辑器CKEDITOR的使用配置(问题注解)

    CKEDITOR是一款非常轻便的富文本编辑器,如上图:参考网上的使用方法,我以.net为例,在aspx页面使用, 准备工作:首先要下载控件包,将解压后的整个文件夹添加到项目根目录. 第一步:引用js, ...

  3. 如何使用CSS Sprites技术进行图片合并

    http://jingyan.baidu.com/article/066074d6757654c3c21cb02d.html

  4. SQL Server 2008将数据导出为脚本

    之前我们要将一个表中的数据导出为脚本,那么只有在网上找一个导出数据的Script,然后运行就可以导出数据脚本了.现在在SQL Server 2008的Management Studio中增加了一个新特 ...

  5. Terminating app due to uncaught exception 'NSUnknownKeyException', reason: xxxx

    出现错误的情景: 使用Swift自定义Cell, 然后将这个Cell在OC中使用, 由于为了能够在OC中使用和使用起来命名比较规范 我在Swift自定义的Cell前加了 @objc(DSProduct ...

  6. swing常用布局

    1,FlowLayout 窗口的默认布局 设置窗口布局方法(下面不重复 setLayout(new FlowLayout()); 设置容器布局方法 比如容器 con1 con1.setLayout(n ...

  7. Oracle数据库之事务

    Oracle数据库之事务 1. 什么是事务 在数据库中事务是工作的逻辑单元,一个事务是由一个或多个完成一组的相关行为的SQL语句组成,通过事务机制确保这一组SQL语句所作的操作要么都成功执行,完成整个 ...

  8. 自定义控件学习之菜鸟笔记一(Hello World)

    一:引言 正在学习自定义控件的开发内容,做为菜鸟勤做笔记自然是必要任务了.本篇为本人学习自定义控件的学习笔记,借此和大家分享一下学习过程吧. 本人学习喜欢先看到具体的实例,然后再深入学习,故先从一个简 ...

  9. QQ原创表情添加

    有时候与QQ好友聊天时会收到一些自己比较喜欢的原创表情,如果我们想把这些QQ不支持直接保存的原创表情保存到电脑上该怎么做呢?我们以原创表情图片为例简单介绍一下. 首先,先建立一个存放表情图片的文件夹. ...

  10. 我是一个云Hosts文件,用来干啥你懂的

    Smarthosts是一个托管在谷歌代码上的项目,您可以轻松利用本项目使用到一份稳定的Hosts文件. 这份Hosts文件可以帮助您顺利打开一些网站,提高某些国外服务的打开或下载速度. http:// ...