[React Testing] className with Shallow Rendering
The React Shallow Renderer test utility lets us inspect the output of a component one level deep. In this lesson, we will examine the rendered output of props, specifically the className prop. We will then use the ES2015 String.includes() method to check that our rendered className includes what we expect.
//className,js
import React from 'react'; const IconComponent = ({icon}) => {
return (
<a className={`fa ${icon}`} rel="icon"/>
)
}; export default IconComponent; //className.spec.js
import React from 'react';
import expect from 'expect';
import expectJSX from 'expect-jsx';
import TestUtils from 'react-addons-test-utils';
import IconComponent from './className'; describe('LikeCOunter', ()=>{ it('should have facebook icon', ()=>{ const renderer = TestUtils.createRenderer();
renderer.render(<IconComponent icon="facebook"/>);
const actual = renderer.getRenderOutput().props.className.includes('facebook');
console.log(renderer.getRenderOutput());
const expected = true;
expect(actual).toEqual(expected);
});
});
[React Testing] className with Shallow Rendering的更多相关文章
- [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] Children with Shallow Rendering
When testing React components, we often want to make sure the rendered output of the component match ...
- [React Testing] Conditional className with Shallow Rendering
Often our components have output that shows differently depending on the props it is given; in this ...
- [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 ...
- 如何使用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] Element types with Shallow Rendering
When you render a component with the Shallow Renderer, you have access to the underlying object. We ...
- [React Testing] Reusing test boilerplate
Setting up a shallow renderer for each test can be redundant, especially when trying to write simila ...
- [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 ...
随机推荐
- 显示推送数据到mq成功,但是mq管理器中消息数量没增长
看服务器上的mq配置,看看mq_log,是不是存储满了?
- 【转】#include,#import,@class的区别
#include #include <> :用于对系统文件的引用,编译器会在系统文件目录下去查找该文件. #include "xx.h ...
- [<DDGuessYouLIkeModel 0x7c99faf0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key star.
出现这个提示是由于以下原因造成: 这里我用到了MJExtension将字典转为模型,但再转为模型的时候,出现这个提示,原因就是因为NSInteger后面多一个一个“*” @property (nona ...
- JavaScript 超类与子类 继承
//超类和子类 继承的实现 function R(w, h) { var date = new Date(); this.width = w; this.height = h; this.create ...
- java事件处理3
鼠标拖动事件 接口MouseMotionListener 两个方法 mouseDragged(MouseEvent)//拖动鼠标 mouseMoved(MouseEvent)//移动鼠标 一个拖动按钮 ...
- seo初学
对前端而言,做网站采用扁平式结构:控制网页链接数量,不能太少,当然也不能太多:其次采用扁平的目录层次,不能超过3次:三:导航优化,最好是文字,如果是图片的话,alt和title必须添加. 面包屑导航: ...
- Nginx并发访问优化
Nginx反向代理并发能力的强弱,直接影响到系统的稳定性.安装Nginx过程,默认配置并不涉及到过多的并发参数,作为产品运行,不得不考虑这些因素.Nginx作为产品运行,官方建议部署到Linux64位 ...
- 修改apk显示或隐藏桌面图标
反编译CM设置,打开AndroidManifest.xml,搜索“DEFAULT”,把他替换为"LAUNCHER",然后回编译,回编译之后签名在用RE放到system\app下该权 ...
- 关于Layouts的分类
ViewGroup ---------------------------------LinearLayout.Relative Layout. AdapterView --------------- ...
- JavaScript 中的非真值
False values 下面这些值将被计算出 false (also known as Falsy values): false undefined null 0 NaN 空字符串 ("& ...