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

    When you render a component with the Shallow Renderer, you have access to the underlying object. We can write lots of useful tests to check that our components are working as expected. In this lesson, we will use the type property on the shallow rendered component to make sure that the root element is what we expect it to be.

    LikeCounter.js

    import React from 'react';
    
    const LikeCounter = ({count}) => {
        return <a href="#">Like: {count}</a>
    }
    
    export default LikeCounter;

    LikeCounter.spec.js:

    import 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(<LikeCounter count={5} />);
            const actual = renderer.getRenderOutput().type;
            const expected = 'a';
            expect(actual).toEqual(expected);
        });
    });
    

      

  • 相关阅读:
    php数组·的方法1-数组的操作
    第十一章:DOM扩展
    第十章:DOM
    hxq的库
    第八章:BOM
    第七章:函数表达式2
    第七章:函数表达式
    第五章:引用类型(一)-Object和Array
    舌尖上的程序猿
    计算矩阵运算的乘法次数
  • 原文地址:https://www.cnblogs.com/Answer1215/p/5100896.html
Copyright © 2011-2022 走看看