[React Testing] Element types with Shallow Rendering
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的更多相关文章
- [React Testing] Conditional className with Shallow Rendering
Often our components have output that shows differently depending on the props it is given; in this ...
- [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- ...
- [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 ...
- React的Element的创建和render
React的Element是React应用程序的最小构建块,它是用来描述我们在屏幕上看到的浏览器页面上的内容. 在React中构建 Element 有两种方式: 1.JSX的方式,JSX不是React ...
- 如何使用TDD和React Testing Library构建健壮的React应用程序
如何使用TDD和React Testing Library构建健壮的React应用程序 当我开始学习React时,我努力的一件事就是以一种既有用又直观的方式来测试我的web应用程序. 每次我想测试它时 ...
- Kettle Unable to get list of element types for namespace 'pentaho'
我把公司的kettle5.0升级到7.0之后遇到了这个问题,困扰了很久,百度谷歌都查不到结果,所以只能自己查找原因. 由于已经被搞好了,现在无法截图了,总之就是下面这行报错,遇到这个错误的同学估计也不 ...
- React Testing All in One
React Testing All in One React 测试 https://reactjs.org/docs/testing.html jest 26.4 https://jestjs.io/ ...
- [React Testing] Children with Shallow Rendering
When testing React components, we often want to make sure the rendered output of the component match ...
- [React Testing] className with Shallow Rendering
The React Shallow Renderer test utility lets us inspect the output of a component one level deep. In ...
随机推荐
- C#Css/Js静态文件压缩--Yui.Compressor.Net
一.Asp.Net 自带静态文件压缩工具包 Microsoft.AspNet.Web.Optimization http://www.nuget.org/packages/Microsoft.AspN ...
- HTML 控件和web控件 OnClientClick和OnClick OnServerClick区别
^_^ 本来对html控件,服务器控件的知识模模糊糊的.今天特地查了相关的知识. 下面是我写代码总结的. 这些事件 主要用于在客户端执行验证,然后决定是否执行服务端事件 (没接触之前就为此 ...
- SAE下的Memcache使用方法
SAE里面有Memcache,可以较大幅度改善数据库的鸭梨~ 之前一直想学习Memcache,却愁于不知如何下手,对这个名词完全没有概念,同时在SAE的文档里面,也很少对于Memcache的使用教程~ ...
- asp.net 定时器
using System;using System.Collections.Generic;using System.Web;using System.IO;using System.Web.Secu ...
- Hadoop源码解析之 rpc通信 client到server通信
rpc是Hadoop分布式底层通信的基础,无论是client和namenode,namenode和datanode,以及yarn新框架之间的通信模式等等都是采用的rpc方式. 下面我们来概要分析一下H ...
- Php ORM 对象关系映射
ORM的全称是Object Relational Mapping,即对象关系映射.它的实质就是将关系数据(库)中的业务数据用对象的形式表示出来,并通过面向对象(Object-Oriented)的方式将 ...
- Oracle数据库之PL/SQL过程与函数
Oracle数据库之PL/SQL过程与函数 PL/SQL块分为匿名块与命名块,命名块又包含子程序.包和触发器. 过程和函数统称为PL/SQL子程序,我们可以将商业逻辑.企业规则写成过程或函数保存到数据 ...
- phpcms v9教程 联动搜索在房地产网站开发中的应用
开发简述:使用phpcms v9系统,修改源文件5个,创建模型:楼盘.出售.出租.中介.小区,增加联动菜单:楼盘,增加用户组:房产中介.实现功能:游客发布信息.会员申请中介.楼盘全方位展示.报名团购. ...
- 4种CSS3效果(360度旋转、旋转放大、放大、移动)
旋转: * { transition:All .4s ease-in-out; -webkit-transition:All .4s ease-in-out; -moz-transition:All ...
- OpenStack点滴01-概览
OpenStack项目由Rackspace和NASA(美国国家航空航天局)共同发起,它是一个旨在为公共及私有云的建设与管理提供软件的开源项目. 作为一个开源云平台,OpenStack的首要任务是简化云 ...