博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[React Testing] Children with Shallow Rendering
阅读量:5142 次
发布时间:2019-06-13

本文共 975 字,大约阅读时间需要 3 分钟。

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(
); const actual = renderer.getRenderOutput(); const expected = "Like: 5"; expect(actual).toIncludeJSX(expected); });});

 

转载于:https://www.cnblogs.com/Answer1215/p/5110434.html

你可能感兴趣的文章
记录:Android中StackOverflow的问题
查看>>
导航,头部,CSS基础
查看>>
[草稿]挂载新硬盘
查看>>
[USACO 2017 Feb Gold] Tutorial
查看>>
关于mysql中GROUP_CONCAT函数的使用
查看>>
OD使用教程20 - 调试篇20
查看>>
Java虚拟机(JVM)默认字符集详解
查看>>
Java Servlet 过滤器与 springmvc 拦截器的区别?
查看>>
(tmp >> 8) & 0xff;
查看>>
linux命令之ifconfig详细解释
查看>>
NAT地址转换
查看>>
Nhibernate 过长的字符串报错 dehydration property
查看>>
Deque - leetcode 【双端队列】
查看>>
gulp插件gulp-ruby-sass和livereload插件
查看>>
免费的大数据学习资料,这一份就足够
查看>>
clientWidth、clientHeight、offsetWidth、offsetHeight以及scrollWidth、scrollHeight
查看>>
企业级应用与互联网应用的区别
查看>>
itext jsp页面打印
查看>>
Perl正则表达式匹配
查看>>
DB Change
查看>>