Test if a component is rendered with the right props with react-testing-library

前端 未结 2 725
耶瑟儿~
耶瑟儿~ 2021-02-01 23:39

I have some components that are rendering another component (FetchNextPageButton) that is already tested in isolation, like these ones:

const News = () => (
          


        
2条回答
  •  星月不相逢
    2021-02-02 00:19

    This is the approach that Kent C. Dodds (the creator of RTL) shared with me after discussing it with him:

    import FetchNextPageButton from 'FetchNextPageButton'
    
    jest.mock('FetchNextPageButton', () => {
      return jest.fn(() => null)
    })
    
    // ... in your test
    expect(FetchNextPageButton).toHaveBeenCalledWith(props, context)
    

提交回复
热议问题