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. Cannot modify header information - headers already sent by

    有时候你在使用 header("Location: http://localhost/myblog/index.php/manager/listview");的时候会出现这个问题, ...

  2. Sql 中常用日期转换Convert(Datetime)

    CONVERT(data_type,expression[,style]) convert(varchar(10),字段名,转换格式) 说明:此样式一般在时间类型(datetime,smalldate ...

  3. Linux下快速搭建DNS服务器

    一.术语解释:TTL Time To Live 缓冲保留时间ORIGIN 属于哪个域@ 代指域IN 开头需要空格SOA 一行记录类型的开始参数:forwarders {} 指向自己无法解析的域名跳转到 ...

  4. iOS 网络与多线程--5.异步Post方式的网络请求(非阻塞)

    通过Post请求方式,异步获取网络数据,异步请求不会阻塞主线程,而会建立一个新的线程来操作. 代码如下 ViewController.h文件 #import <UIKit/UIKit.h> ...

  5. Php GMP

    GMP是The GNU MP Bignum Library,是一个开源的数学运算库,它可以用于任意精度的数学运算,包括有符号整数.有理数和浮点数.它本身并没有精度限制,只取决于机器的硬件情况. 本函数 ...

  6. angularjs不同页面间controller传参方式,使用service封装sessionStorage

    这里分享一个我在实际项目中,使用service封装的一个依赖sessionStorage的传参服务. 这里先说下大背景,在我们的实际开发中,登陆之后一般会存在一个token,这个token将会贯穿全场 ...

  7. Y - Design T-Shirt(第二季水)

    Description Soon after he decided to design a T-shirt for our Algorithm Board on Free-City BBS, XKA ...

  8. 磁盘阵列RAID

                                                                                  磁盘阵列RAID 年提出的.RAID名为独立 ...

  9. Mysql 索引案例学习

    理解索引最好的办法是结合示例,所以这里准备了一个索引的案例. 假设要设计一个在线约会网站,用户信息表有很多列,包裹国家,地区,城市,性别,眼睛颜色,等等.完整必须支持上面这些特征的各种组合来搜索用户, ...

  10. code:blocks 编译环境设置

    1.  支持C99 在菜单settings->compiler settings->comiler settings->Other options 添加: -std=c99 2. 支 ...