[React Testing] Reusing test boilerplate
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的更多相关文章
- 如何使用TDD和React Testing Library构建健壮的React应用程序
如何使用TDD和React Testing Library构建健壮的React应用程序 当我开始学习React时,我努力的一件事就是以一种既有用又直观的方式来测试我的web应用程序. 每次我想测试它时 ...
- React Testing All in One
React Testing All in One React 测试 https://reactjs.org/docs/testing.html jest 26.4 https://jestjs.io/ ...
- [React Testing] Children with Shallow Rendering
When testing React components, we often want to make sure the rendered output of the component match ...
- [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 ...
- [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- ...
- [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 ...
- [React & Testing] Simulate Event testing
Here we want to test a toggle button component, when the button was click, state should change, styl ...
- [React & Testing] Snapshot testings
For example we have a React comonent: -- A toggle button, we want to test. When it si toggle on, the ...
- [React Testing] The Redux Store - Multiple Actions
When using Redux, we can test that our application state changes are working by testing that dispatc ...
随机推荐
- 最全的ORACLE-SQL笔记
-- 首先,以超级管理员的身份登录oracle sqlplus sys/bjsxt as sysdba --然后,解除对scott用户的锁 alter user scott account unloc ...
- Java中如何判断当前环境是大端字节顺序还是小端字节顺序
Java非字节类型的基本类型,除了布尔型都是由组合在一起的几个字节组成的.这些数据类 型及其大小总结在表 2-1 中. 表:基本数据类型及其大小 数据类型 大小(以字节表示) Byte 1 Char ...
- angularjs中ng-attr的用法
<!DOCTYPE html> <html lang="zh-CN" ng-app="app"> <head> <me ...
- prototype constructor __proto__
constructor, prototype, __proto__ 详解
- (五)Angularjs - 依赖注入
如何找到API? AngularJS提供了一些功能的封装,但是当你试图通过全局对象angular去 访问这些功能时,却发现与以往遇到的库大不相同. 比如,AngularJS暴露了一个全局对象:angu ...
- IO流文件字符输入输出流,缓冲流
由于字节输入输出流在操纵Unicode字符时可能有乱码现象 于是就有了操作字符的输入输出流 Reader ,Writer和他们的子类FileReader,FileWrite(其实就是用来辅助构造的 W ...
- seo初学
对前端而言,做网站采用扁平式结构:控制网页链接数量,不能太少,当然也不能太多:其次采用扁平的目录层次,不能超过3次:三:导航优化,最好是文字,如果是图片的话,alt和title必须添加. 面包屑导航: ...
- 0X0000124
求教卡饭网友,都快疯掉了. 最近搞设计,电脑频发出现蓝屏,今晚都出现三次了,新装的win7 64位系统,都是安装的原版光驱. 错误代码基本上都是:0x00000124 (0x000 ...
- C++通过OCCI操作Oracle数据库详解
1.安装OCCI 如果oracle数据库默认没有安装OCCI,可以自己从官网上下载与自己数据库版本一致的API,其中包含四个软件包: oracle-instantclient-sqlplus-10.2 ...
- JS操作css的float属性的特殊写法
使用js操作css属性的写法是有一定的规律的: 1.对于没有中划线的css属性一般直接使用style.属性名即可. 如:obj.style.margin,obj.style.width,obj.sty ...