react-testing-library why is toBeInTheDocument() not a function

后端 未结 5 1094
别跟我提以往
别跟我提以往 2021-02-11 15:35

Here is my code for a tooltip that toggles the CSS property display: block on MouseOver and on Mouse Out display: none.

 it(\'should sho         


        
5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-11 15:46

    As mentioned by Giorgio, you need to install jest-dom. Here is what worked for me:

    (I was using typescript)

    npm i --save-dev @testing-library/jest-dom
    

    Then add an import to your setupTests.ts

    import '@testing-library/jest-dom/extend-expect';
    

    Then in your jest.config.js you can load it via:

    "setupFilesAfterEnv": [
        "/src/setuptests.ts"
      ]
    
    
    

提交回复
热议问题