[React Testing] Children with Shallow Rendering
2016-01-07 16:53
501 查看
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
childrenprop, or a subset of the
childrenprop. 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 Native入门——组件构成及生命周期简介
- ReactiveCocoa源码拆分解析(五)
- [React Testing] Reusing test boilerplate
- Reactance (对抗)
- 【React Native开发】React Native开发IDE安装及配置(2)
- Reactivity(反应性)
- 通往全栈工程师的捷径 —— react
- React Native通信机制详解
- [React Testing] Conditional className with Shallow Rendering
- [React Testing] className with Shallow Rendering
- ReactJS 官网案例分析
- 函数响应式编程—ReactiveCocoa 使用入门
- Scala 并发编程之react和loop
- React 入门实例教程
- React 入门实例教程
- react native运行报错
- 在SublimeText上搭建ReactJS开发环境
- H5、React Native、Native应用对比分析
- React-Native安装时的坑
- ReactiveCocoa v2.5 源码解析 之 架构总览