When you render a component with the Shallow Renderer, you have access to the underlying object. We can write lots of useful tests to check that our components are working as expected. In this lesson, we will use the type property on the shallow rendered component to make sure that the root element is what we expect it to be.

LikeCounter.js

import React from 'react';

const LikeCounter = ({count}) => {
return <a href="#">Like: {count}</a>
} export default LikeCounter;

LikeCounter.spec.js:

import React from 'react';
import expect from 'expect';
import expectJSX from 'expect-jsx';
import TestUtils from 'react-addons-test-utils';
import LikeCounter from './likeCounter'; describe('LikeCOunter', ()=>{ it('should be a link', ()=>{
const renderer = TestUtils.createRenderer();
renderer.render(<LikeCounter count={5} />);
const actual = renderer.getRenderOutput().type;
const expected = 'a';
expect(actual).toEqual(expected);
});
});

  

[React Testing] Element types with Shallow Rendering的更多相关文章

  1. [React Testing] Conditional className with Shallow Rendering

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

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

  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. React的Element的创建和render

    React的Element是React应用程序的最小构建块,它是用来描述我们在屏幕上看到的浏览器页面上的内容. 在React中构建 Element 有两种方式: 1.JSX的方式,JSX不是React ...

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

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

  6. Kettle Unable to get list of element types for namespace 'pentaho'

    我把公司的kettle5.0升级到7.0之后遇到了这个问题,困扰了很久,百度谷歌都查不到结果,所以只能自己查找原因. 由于已经被搞好了,现在无法截图了,总之就是下面这行报错,遇到这个错误的同学估计也不 ...

  7. React Testing All in One

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

  8. [React Testing] Children with Shallow Rendering

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

  9. [React Testing] className with Shallow Rendering

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

随机推荐

  1. congos 日期控件的简单使用

    congos 添加html的标签,然后写上js的代码,这段代码的功能是得到前一天的日期. <input type="button" value="查询" ...

  2. 汇编test和cmp区别

    来自http://tunps.com/assembly-test-and-cmp 看过破解教程,都知道test,cmp是比较关键,可是我一直不清楚它们究竟是怎么比较的,最后下决心找了很多资料,和大家一 ...

  3. (转)Eclipse快捷键大全,导包快捷键:ctrl+Shift+/

    Ctrl+1 快速修复(最经典的快捷键,就不用多说了)Ctrl+D: 删除当前行 Ctrl+Alt+↓ 复制当前行到下一行(复制增加)Ctrl+Alt+↑ 复制当前行到上一行(复制增加)Alt+↓ 当 ...

  4. 转载:详解CSS选择器、优先级与匹配原

    转载网址:http://polaris1119.javaeye.com/blog/764428 文章就CSS选择器的优先级问题做了一些总结,严格来讲,选择器的种类可以分为三种:标签名选择器.类选择器和 ...

  5. asp.net 防止页面刷新或后退引起重复提交

     项目中经常遇到刷新后重复的向数据库增加一条相同的记录,造成数据重复,如何规避这些问题呢?下面我们就一起讨论一下在asp.net怎样防止页面刷新或后退引起重复提交数据的问题: 其实asp.net防止刷 ...

  6. DedeCMS标签 PHP判断语句写法

    缩略图标签的判断写法,如果有图片就显示,没图片就显示别的. {dede:field name=litpic runphp='yes'} if(!empty(@me)) { @me="< ...

  7. java-map-IdentityHashMap

    1.背景 今天翻开IdentityHashMap的时候,就傻眼了,这个到底是个逻辑啊,我的程序代码如下: IdentityHashMap<String,String> identityHa ...

  8. 【问题】pod setup 问题

    安装pod setup 的时候,可能会安装失败,可以多试几次,但是如果一直失败,那就是由问题了. 解决办法: 1. 分别执行下面命令卸载cocoapods和xcodeproj,如果你的机器上面有多个版 ...

  9. 复杂事件处理引擎—Esper入门

    说明: 以下内容,可以参考Esper官方网站<Qucik start & Tutorial >(顺序做了部分调整). PS:因为英语水平有限(大学期间刚过CET4的英语小盲童一枚) ...

  10. win8 在哪找画图工具

    把鼠标放在右上角,然后往下拉,出现搜索图标,如图: 在‘搜索’输入‘画图’ 打开即可使用.