[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 ...
随机推荐
- 在C#中internal关键字是什么意思?和protected internal区别
我来补充一下,对于一些大型的项目,通常由很多个DLL文件组成,引用了这些DLL,就能访问DLL里面的类和类里面的方法.比如,你写了一个记录日志的DLL,任何项目只要引用此DLL就能实现记录日志的功能, ...
- 学习日记-----ORM
ORM ORM(Object Relation Mapping)对象关系映射 实质:将数据库中 的业务数据用对象的形式表现出来,使用ORM在业务逻辑层和数据访问层之间充当桥梁 核心原则: 简单性 传达 ...
- JavaScript 之 使用 XMLHttpRequest 上传文件
<div id="div1"> <input type="file" id="uploadfile" style=&quo ...
- angularjs中的绑定策略“@”,“=”,“&”实例
<!DOCTYPE html> <html lang="zh-CN" ng-app="app"> <head> <me ...
- 武汉科技大学ACM:1007: 不高兴的津津
Problem Description 津津上初中了.妈妈认为津津应该更加用功学习,所以津津除了上学之外,还要参加妈妈为她 报名的各科复习班.另外每周妈妈还会送她去学习朗诵.舞蹈和钢琴.但是津津如果一 ...
- thinkphp M 和模板用法
<?phpnamespace Home\Controller;use Think\Controller;class IndexController extends Controller { pu ...
- JQUERY1.9学习笔记 之基本过滤器(四) 首元素选择器
首元素选择器:jQuery( ":first" ) <!DOCTYPE html><html lang="zh-cn"><head ...
- discuz php判断是手机访问还是电脑访问网站
首先在模块处填入代码: //手机网页跳转 //如果检测到访问的浏览器为下列一个指定的移动浏览器 则返回true function is_mobile(){ $regex_match="/(n ...
- DEVICE_OBJECT结构参数
typedef struct DECLSPEC_ALIGN(MEMORY_ALLOCATION_ALIGNMENT) _DEVICE_OBJECT { CSHORT Type; USHORT Size ...
- PHP浮点数的一个常见问题的解答
作者: Laruence 本文地址: http://www.laruence.com/2013/03/26/2884.html 转载请注明出处 关于PHP的浮点数, 我之前写过一篇文章: 关于PHP浮 ...