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

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

Often our components have output that shows differently depending on the props it is given; in this lesson, we go over how to compare the className prop element tree output based on conditional input.

 

// LikeCounter.jsimport React from 'react';import classnames from 'classnames';const LikeCounter = ({count, isActive}) => {    return Like: {count}}export default LikeCounter;// LikeCounter.spec.jsimport 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(
); const actual = renderer.getRenderOutput().type; const expected = 'a'; expect(actual).toEqual(expected); });});describe('active class', ()=>{ it('should have active class based on isActive props: true', ()=>{ const renderer = TestUtils.createRenderer(); renderer.render(
); const actual = renderer.getRenderOutput().props.className.includes('LikeCounter--active'); const expected = true; expect(actual).toEqual(expected); }); it('should have active class based on isActive props: false', ()=>{ const renderer = TestUtils.createRenderer(); renderer.render(
); const actual = renderer.getRenderOutput().props.className.includes('LikeCounter--active'); const expected = false; expect(actual).toEqual(expected); });});

 

转载地址:http://wsrxl.baihongyu.com/

你可能感兴趣的文章
Java SE核心之一:常用类,包装类,其他基本数据类型包装类。
查看>>
郑捷《机器学习算法原理与编程实践》学习笔记(第二章 中文文本分类(一))...
查看>>
python (ploit)
查看>>
Android 用achartengine 画折线图怎么显示不正确
查看>>
程序简单的测试与升级(暨实践第一次作业)
查看>>
信号处理
查看>>
【100题】第五十九题 用C++编写不能被继承的类
查看>>
轻描淡写
查看>>
mysql基本操作
查看>>
39.CSS3弹性伸缩布局【下】
查看>>
[javascript]图解+注释版 Ext.extend()
查看>>
我的前端工具集(七)div背景网格
查看>>
linux 下mongo 基础配置
查看>>
【Dubbo实战】 Dubbo+Zookeeper+Spring整合应用篇-Dubbo基于Zookeeper实现分布式服务(转)...
查看>>
JUnit单元测试中的setUpBeforeClass()、tearDownAfterClass()、setUp()、tearDown()方法小结
查看>>
java之jvm学习笔记六(实践写自己的安全管理器)
查看>>
Docker容器查看ip地址
查看>>
在PC端或移动端应用中接入商业QQ
查看>>
将python3.6软件的py文件打包成exe程序
查看>>
DataTable 排序
查看>>