[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 ...
随机推荐
- Js实现简单的联动,无数据库版本
<html> <head> <title></title> <script language="javascript" typ ...
- 一个CSS小测试
<!DOCTYPE html> <html> <head> <style type="text/css"> body{ margin ...
- securecrt简介
SecureCRT是最常用的终端仿真程序,简单的说就是Windows下登录UNIX或Liunx服务器主机的软件,本文主要介绍SecureCRT的使用方法和技巧 VanDyke CRT 和 VanDyk ...
- 你好,C++(30)“大事化小,小事化了”5.4.3 工资程序成长记:函数
5.4.3 工资程序成长记:函数 自从上次小陈“程序员”的工资程序得到老板的夸奖,口头许诺给他涨工资以后,老板再也没有找过他,涨工资的事自然也就没有下文了.这天,老板又突然召他去办公室.这下可把小陈高 ...
- linux入门。删除不用到内核,为boot分区释放空间
在终端中输入如下命令: dpkg --get-selections|grep linux-image 这时会列出系统中所有到内核. 你可以使用 uname -a 查看你当前使用到内核. 然后用 sud ...
- Linux入门 (笔记)
Man can conquer nature. "人定胜天" 一.基本操作 1.重要快捷键 Tab 补全命令.目录.参数.文件名等 Ctrl+c 强制终止当前的程序 Ctrl+ ...
- kafka教程
一.理论介绍(一)相关资料1.官方资料,非常详细: http://kafka.apache.org/documentation.html#quickstart2.有一篇翻译版,基本一致,有些细节不 ...
- Dapper试用简例
1.选择3.5以上框架在新建项目中引用Dapper.dll. 2.在后台写代码,代码写出来后感觉以前学的都白学了. 3. using Dapper; using System; using Syste ...
- NSSet和NSMutableSet 确保数据的唯一性--备
NSSet和NSMutableSet是无序的, 但是它保证数据的唯一性.当插入相同的数据时,不会有任何效果.从内部实现来说是hash表,所以可以常数时间内查找一个数据. 1.NSSet的使用 [NSS ...
- The 500 Most Commonly Used Words in the English Language
Based on the combined results of British English, American English and Australian English surveys of ...