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. mysql慢查优化总结

    1.优化sql语句结构 or改成union,使用start,limit 先只查询出所有的id,然后再排序.如果查询出所有的id仍然很慢,就要仔细考虑了. 2.添加索引 mysql每次查询只能使用一个索 ...

  2. zepto源码研究 - ajax.js($.ajaxJSONP 的分析)

    简要:jsonp是一种服务器和客户端信息传递方式,一般是利用script元素赋值src来发起请求.一般凡是带有src属性的元素发起的请求都是可以跨域的. 那么jsonp是如何获取服务器的数据的呢? j ...

  3. Spring Boot Web项目之参数绑定

    一.@RequestParam 这个注解用来绑定单个请求数据,既可以是url中的参数,也可以是表单提交的参数和上传的文件 它有三个属性,value用于设置参数名,defaultValue用于对参数设置 ...

  4. php笔试题1

    PHP 基础知识部分 1. 求$a的值 复制代码 代码如下: $a = "hello"; $b = &$a; unset($b); $b = "world&quo ...

  5. Delphi XE7 开发ActiveX 及在IntraWeb下调试

    最近学习DelphiXE7下Intraweb开发,Intraweb完全服务器端运行使得FastReport报表系统无法在客户端运行,当然网上也有一大堆解决方案,例如导出到PDF后,给出连接,让客户点击 ...

  6. python命令行运行在win和Linux系统的不同

    今天,在完成一个小的python习题,习题的主要内容是读取一个帮助模块,并保存到本地文件. 知道是用pydoc进行模块的读取,但是在windows系统下,调用os模块之后,结果总是为空. 核心语句: ...

  7. gtk程序如何进行编译

    程序名: gtk_example.c    生成目标文件:gtk_example gcc gtk_example.c -o gtk_example   `pkg-config --libs --cfl ...

  8. map(int, ..) 与 int() 的区别

    >>> map(int,') [0] >>> int('-1') -1 >>> map(int, l[1]) Traceback (most re ...

  9. cocos2d(粒子效果编辑器)

    ParticleDesigner  for  Mac下载地址:http://www.cocoachina.com/bbs/read.php?tid=108339 最近在做一款粒子编辑器 其实就是在co ...

  10. web登录与授权

    web开发已经流行了很多年,登录与授权也基本有一套通用的流程,下面是我自己常用的登录与授权方式,欢迎大家讨论与吐槽. 概念: 登录是过程,授权是结果.登录只是为了获得页面的访问权限 or 操作权限 o ...