When testing React components, we often want to make sure the rendered output of the component matches what we expect. With the React Shallow Renderer, we can check the entire rendered output of a component, the children prop, or a subset of the children prop. We can also use 3rd party libraries to check that this element tree includes a specific piece. In this lesson we will walk through examples of each.

import React from 'react';
import expect from 'expect';
import expectJSX from 'expect-jsx';
expect.extend(expectJSX);
import TestUtils from 'react-addons-test-utils';
import LikeCounter from './likeCounter'; describe('like counter', ()=>{ it('should render the like count correctly', ()=>{
const renderer = TestUtils.createRenderer();
renderer.render(<LikeCounter count={5} />);
const actual = renderer.getRenderOutput();
const expected = "Like: 5";
expect(actual).toIncludeJSX(expected);
});
});

[React Testing] Children 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] className with Shallow Rendering

    The React Shallow Renderer test utility lets us inspect the output of a component one level deep. In ...

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

  4. 如何使用TDD和React Testing Library构建健壮的React应用程序

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

  5. React Testing All in One

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

  6. [React Testing] Element types with Shallow Rendering

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

  7. [React Testing] Conditional className with Shallow Rendering

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

  8. [React & Testing] Simulate Event testing

    Here we want to test a toggle button component, when the button was click, state should change, styl ...

  9. [React & Testing] Snapshot testings

    For example we have a React comonent: -- A toggle button, we want to test. When it si toggle on, the ...

随机推荐

  1. sql 判断表、列、视图等是否存在

    1 判断数据库是否存在 if exists (select * from sys.databases where name = '数据库名')     drop database [数据库名] 2 判 ...

  2. Windows计划任务 未能启动

    近期在windows server 2003上运行的备份脚本,在7月23日之后,没再运行,在计划任务里看到的状态是:未能启动.结果手动运行了一下备份脚本,没有问题,可以正常运行,但是在计划任务里为什么 ...

  3. 如何安装Oracle Database 11g数据库

    先选择你适合你的系统版本,32位系统的请选择32位的,64位系统可以使用32位也可以使用64位,建议采用64位的! 适用于 Microsoft Windows(32 位)的 Oracle Databa ...

  4. HashTable 及应用

    HashTable-散列表/哈希表,是根据关键字(key)而直接访问在内存存储位置的数据结构. 它通过一个关键值的函数将所需的数据映射到表中的位置来访问数据,这个映射函数叫做散列函数,存放记录的数组叫 ...

  5. geoserver + postgis+postgresql+agslib.swc

    运用开源的geoserver+postgis+postgresql+arcgis for flex api 开发地图应用系统. 1.Geoserver GeoServer 是 OpenGIS Web ...

  6. Java学习笔记——SequenceInputStream类合并文件的综合举例分析

    SequenceInputStream 介绍 SequenceInputStream 类表示其他输入流的逻辑串联,即文件的合并. 它从输入流的有序集合开始,并从第一个输入流开始读取,直到到达文件末尾, ...

  7. Nginx常用Rewrite伪静态法则

    信赖此刻大部门用Linux VPS的伴侣都在利用这个敏捷传布的Nginx,本日就清算一下最常见的PHP法式的Rewrite(伪静态法则). Wordpress: location / {index i ...

  8. PHPCMS 插件开发教程及经验谈

    虽说 PHPCMS 开源,但其它开发文档及参考资料实在少得可怜.进行二次开发时,自己还得慢慢去研究它的代码,实在让人郁闷. PHPCMS 的“Baibu/Google地图”实在有待改进,对于数据量比较 ...

  9. Android Init进程命令的执行和服务的启动

    这里开始分析init进程中配置文件的解析,在配置文件中的命令的执行和服务的启动. 首先init是一个可执行文件,它的对应的Makfile是init/Android.mk. Android.mk定义了i ...

  10. Number对象

    <script type="text/javascript"> /* Number对象. 创建Number对象的方式: 方式1: var 变量= new Number( ...