How to test React PropTypes through Jest?

前端 未结 6 1161
终归单人心
终归单人心 2020-12-25 12:22

I\'m writing Jest tests for my React code and hoping to make use of/test the PropType checks. I am quite new to the Javascript universe. I\'m using npm to install reac

6条回答
  •  北海茫月
    2020-12-25 12:43

    Since ReactJS will only send warnings to the console but will not actually throw an error, I test prop values in this way:

    var myTestElement = TestUtils.renderIntoDocument(
     );
    
    it("check MyTestElement props", function() {
    
       expect( typeof myTestElement.props.height ).toEqual ( 'number' );
    
    });
    

提交回复
热议问题