How do you mock useLocation() pathname using shallow test enzyme Reactjs?

前端 未结 3 2458
别那么骄傲
别那么骄傲 2021-02-20 18:56

I have header component like below:

import { useLocation } from \"react-router-dom\";

const Header = () => {
   let route = useLocation().pathname; 
   retur         


        
3条回答
  •  一个人的身影
    2021-02-20 19:19

    Have you tried:

    describe("
    ", () => { it("call the header component", () => { const wrapper = shallow(
    ); expect(wrapper.find(Header).dive().find(ComponentA)).toHaveLength(1); }); });

    When you use shallow only the first lvl is rendered, so you need to use dive to render another component.

提交回复
热议问题