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. Android Http请求失败解决方法

    1.MainActivity.java 文件中的onCreate方法改成如下: @SuppressLint("NewApi") @Override protected void o ...

  2. Android应用清单文件:AndroidManifest.xml

    AndroidMainfest.xml清单文件是每个Android项目所必需的,它是整个Android应用的全家描述文件. <?xml version="1.0" encod ...

  3. 原生js实现的放大镜效果

    这是我用原生js写的放大镜效果,与各种各样的框架技术相比,我喜欢使用原生的js,在这里,想和大家一起谈谈原生和框架技术的理解与个人喜好. <!DOCTYPE HTML><html&g ...

  4. Jenkins修改域认证,非域用户忘记密码处理

    一.认证域地址修改 1. 编辑配置文件 vi $JENKINS_HOME/jenkins/config.xml 2.修改如下内容: <securityRealm class="huds ...

  5. 添加view类图中的二级菜单

    void CFafdsafasdfasfasView::OnLButtonDown(UINT nFlags, CPoint point) { // TODO: Add your message han ...

  6. Spring4.0学习笔记(4) —— 使用外部属性文件

    1.配置xml文件 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="htt ...

  7. php javascript

    php100:103:Jquery javascript javascript:网页用来改进设计.验证表单.检测浏览器.创建cookies. Javascript(简称JS) 和 HTML 标签一样都 ...

  8. delphi : 取得网页源码内容

    取得网页的源码内容的函数以及调用方法供大家参考: program geturl; uses wininet, windows; //取网页内容 function StrPas(const Str: P ...

  9. C# 文件创建时间,修改时间

    System.IO.FileInfo fi = new System.IO.FileInfo(@"D:\site\EKECMS\skin\Grey\default#.html"); ...

  10. 转:VC中WORD,DWORD,unsigned long,unsigned short的区别(转)

    typedef unsigned long       DWORD;typedef int                 BOOL;typedef unsigned char       BYTE; ...