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的更多相关文章

  1. [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- ...

  2. [React Testing] Children with Shallow Rendering

    When testing React components, we often want to make sure the rendered output of the component match ...

  3. [React Testing] Conditional className with Shallow Rendering

    Often our components have output that shows differently depending on the props it is given; in this ...

  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. 如何使用TDD和React Testing Library构建健壮的React应用程序

    如何使用TDD和React Testing Library构建健壮的React应用程序 当我开始学习React时,我努力的一件事就是以一种既有用又直观的方式来测试我的web应用程序. 每次我想测试它时 ...

  6. React Testing All in One

    React Testing All in One React 测试 https://reactjs.org/docs/testing.html jest 26.4 https://jestjs.io/ ...

  7. [React Testing] Element types with Shallow Rendering

    When you render a component with the Shallow Renderer, you have access to the underlying object. We ...

  8. [React Testing] Reusing test boilerplate

    Setting up a shallow renderer for each test can be redundant, especially when trying to write simila ...

  9. [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 ...

随机推荐

  1. TODO、FIXME和XXX转载

    代码中特殊的注释技术——TODO.FIXME和XXX的用处 // TODO Auto-generated method stub

  2. SQL中删除同一字段中重复的值

    /////////////////////目地:ZDJZ_DIS中 name字段有重复的值,删除重复的值 DELETE * FROM ZDJZ_DIS WHERE NAME IN (select NA ...

  3. 逆天的IE7中,绝对定位元素之间的遮盖问题

    个人比较支持IE9以上的版本,认为他们的样式和效果都是比较人性化的,不过很多时候还是不得不考虑其他版本浏览器的感受,这里IE6就不用考虑他了,这货简直就是IT史上的奇葩,这里要说一个IE7的绝对定位和 ...

  4. CSS中常用中文字体转Unicode编码表

    中文名 英文名 Unicode Unicode 2 Mac OS 华文细黑 STHeiti Light [STXihei] \534E\6587\7EC6\9ED1 华文细黑 华文黑体 STHeiti ...

  5. C程序设计语言练习题1-15

    练习1-15 重新编写1.2节中的温度转换程序,使用函数实现温度转换计算. 代码如下: #include <stdio.h> // 包含标准库的信息. float fahrToCelsiu ...

  6. Spark 启动过程(standalone)

    Spark启动过程 正常启动Spark集群时往往使用start-all.sh ,此脚本中通过调用start-master.sh和start-slaves.sh启动mater及workers节点. 1. ...

  7. ECharts使用心得——矩阵树图

    1. 缘起 最近实验室 boss 让用矩形树图做一下研究数据的展示,囧,矩形树图是什么鬼.问了问师兄,说用 R 语言可以实现,让我去研究一下. = =,那这周不是不用干别的了. 刚好最近在研究百度出的 ...

  8. android更新SDK时候丢失annotations.jar 导致支持库报错

    I am trying to update my Android SDK Tools to 17 rev. and I updated usign SDK Tools but in Propertie ...

  9. 使用john破解ubuntu(linux)9.10密码

    Title:使用john破解ubuntu(linux)9.10密码 --2011-11-23 15:00 ubuntu 9.10的账户密码加密方式改用sha512了,默认的john是破不了的,还好官方 ...

  10. javascript scroll事件

    http://developer.51cto.com/art/201107/277994.htm onscroll事件 window.onscroll|| document.onscroll var ...