使用 react-testing-library,以下测试有效:
it( 'renders popular search terms, with links to search urls', () => {
waitFor(() => {
const popularSearch = screen.getByText( Copywriting.buyer.shop.popularSearch, {}, { timeout: 5000 })
expect( popularSearch ).toBeInTheDocument()
const popularSearchPills = screen.findAllByTestId( 'pill' )
expect( popularSearchPills.length ).toBeGreaterThan( 0 )
const hrefs = popularSearchPills.map( pill => pill.href )
expect( hrefs.filter( urlIsValidAndNotBaseUrl )).not.toHaveLength( 0 )
})
})
Run Code Online (Sandbox Code Playgroud)
但是以下测试曾经有效,但现在失败了:
it( 'renders popular search terms, with links to search urls', async () => {
const popularSearch = await screen.findByText( Copywriting.buyer.shop.popularSearch ) …Run Code Online (Sandbox Code Playgroud) testing reactjs redux-saga react-redux react-testing-library