[React Testing] Children with Shallow Rendering

时间:2022-09-12 09:18:16

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. &lbrack;React Testing&rsqb; Intro to Shallow Rendering

    In this lesson, we walk through how to use one of React's Test Utilities (from thereact-addons-test- ...

  2. &lbrack;React Testing&rsqb; className with Shallow Rendering

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

  3. &lbrack;React Testing&rsqb; 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. &lbrack;React Testing&rsqb; Element types with Shallow Rendering

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

  7. &lbrack;React Testing&rsqb; Conditional className with Shallow Rendering

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

  8. &lbrack;React &amp&semi; Testing&rsqb; Simulate Event testing

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

  9. &lbrack;React &amp&semi; Testing&rsqb; Snapshot testings

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

随机推荐

  1. junit的学习

    junit 是一种单元检测的工具包,他能解决的问题主要是有两点 : 1.  不用将方法都调到main方法去执行一次来看结果 2.  测试的结果可以不用我们人工去对比,这里主要使用的是junit的断言类 ...

  2. IDApython教程(一)

    IDAPython是IDA的一个功能强大的扩展特性,对外提供了大量的IDA API调用.另外,还能在使用python 脚本语言的过程中获得能力提升,所以我强烈推荐所有的逆向工程师使用它. 然而不幸的是 ...

  3. 通过JdbcTemplate编写数据访问(二十八)

    数据源配置 在我们访问数据库的时候,需要先配置一个数据源,下面分别介绍一下几种不同的数据库配置方式. 首先,为了连接数据库需要引入jdbc支持,在pom.xml中引入如下配置: 1 2 3 4 &lt ...

  4. 关于ORA-12505&comma; TNS&colon;listener does not currently know of SID given in connect descriptor报错问题解决办法

    1.本机tnsnames.ora 配置如下 test4= (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.1 ...

  5. &lbrack;leetcode&rsqb;301&period; Remove Invalid Parentheses 去除无效括号

    Remove the minimum number of invalid parentheses in order to make the input string valid. Return all ...

  6. Java开篇

    首先致敬Java之父:JAMES GOSLING 一.什么是JDK,JRE,JVM?     1.JDK(Java Development Kit) Java开发工具包.        JDK = 开 ...

  7. &lbrack;19&sol;04&sol;28-星期日&rsqb; GOF23&lowbar;结构型模式&lpar;享元模式&rpar;

    一.享元模式(FlyWeight,轻量级) [共享类与非共享类] /*** *FlyweightFactory享元工厂类: 创建并管理享元对象,享元池一般设计成键值对 */ package cn.sx ...

  8. logstash&plus;elasticsearch 错误摘记

    [2017-09-17T06:00:22,511][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [] uncaught exception ...

  9. json字符串和json对象的转换

    http://www.json.org/提供了一个json2.js,这样ie8(兼容模式),ie7和ie6就可以支持JSON对象以及其stringify()和parse()方法: parse用于从一个 ...

  10. fullCalendar动态获取数据

    fullCalendar http://fullcalendar.io/docs/event_data/events_function $('#calendar').fullCalendar({ he ...