zoukankan      html  css  js  c++  java
  • [React Testing] className with Shallow Rendering

    The React Shallow Renderer test utility lets us inspect the output of a component one level deep. In this lesson, we will examine the rendered output of props, specifically the className prop. We will then use the ES2015 String.includes() method to check that our rendered className includes what we expect.

    //className,js
    import React from 'react';
    
    const IconComponent = ({icon}) => {
        return (
            <a className={`fa ${icon}`} rel="icon"/>
        )
    };
    
    export default IconComponent;
    
    //className.spec.js
    import React from 'react';
    import expect from 'expect';
    import expectJSX from 'expect-jsx';
    import TestUtils from 'react-addons-test-utils';
    import IconComponent from './className';
    
    describe('LikeCOunter', ()=>{
    
        it('should have facebook icon', ()=>{
    
            const renderer = TestUtils.createRenderer();
            renderer.render(<IconComponent icon="facebook"/>);
            const actual = renderer.getRenderOutput().props.className.includes('facebook');
            console.log(renderer.getRenderOutput());
            const expected = true;
            expect(actual).toEqual(expected);
        });
    });
  • 相关阅读:
    「manacher」
    「回文自动机」
    「可持久化数据结构(平衡树、trie树、线段树) 」
    「后缀数组」
    「LCT」
    「网络流」
    「一些知识点」
    「至今不会」
    「推荐博客」
    「最小生成树」
  • 原文地址:https://www.cnblogs.com/Answer1215/p/5108011.html
Copyright © 2011-2022 走看看