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);
        });
    });
  • 相关阅读:
    2019南京网络赛 D Robots 期望dp
    【ICPC2019银川站】K
    【ICPC2019南昌站】I
    【SEERC 2019】E
    电子取证知识和经验总结
    CCPC2020绵阳站游记
    【CCPC2020绵阳站】J
    【CCPC2020绵阳站】K
    【SWERC 2019-20】K Birdwatching
    【HAOI2012】容易题
  • 原文地址:https://www.cnblogs.com/Answer1215/p/5108011.html
Copyright © 2011-2022 走看看