[React Testing] Reusing test boilerplate
2016-01-07 15:12
681 查看
Setting up a shallow renderer for each test can be redundant, especially when trying to write similar tests that have slight tweaks. In this lesson, we go over how you can reduce some of the overlapping code so that each test only contains the unique pieces of the test.
describe('active class', ()=>{ function renderLikeCounter(isActive){ const renderer = TestUtils.createRenderer(); renderer.render(<LikeCounter count={5} isActive={isActive}/>); return renderer.getRenderOutput().props.className.includes('LikeCounter--active'); } it('should have active class based on isActive props: true', ()=>{ expect(renderLikeCounter(true)).toEqual(true); }); it('should have active class based on isActive props: false', ()=>{ expect(renderLikeCounter(false)).toEqual(false); }); });
相关文章推荐
- 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 源码解析 之 架构总览
- React State学习
- react-native 之布局篇
- H5、React Native、Native应用对比分析