How to test React PropTypes through Jest?

前端 未结 6 1100
终归单人心
终归单人心 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 13:06

    A new package jest-prop-type-error is simple to add and fails on PropType errors:

    Install via:

    yarn add -D jest-prop-type-error
    

    Then add the following to your package.json's setupFiles in the jest section:

    "setupFiles": [
      "jest-prop-type-error"
    ]
    

提交回复
热议问题