import { render, waitFor } from '@testing-library/react'; import React from 'react'; import { createSearchClient, createMultiSearchResponse, createSingleSearchResponse, } from '../../../../../test/mock'; import { InstantSearchHooksTestWrapper } from '../../../../../test/utils'; import { Hits } from '../Hits'; describe('Hits', () => { test('renders with default props', async () => { const { container } = render( ); await waitFor(() => { expect(container.querySelector('.ais-Hits')).toMatchInlineSnapshot(`
`); }); }); test('renders with a non-default hit shape', async () => { type CustomHit = { somethingSpecial: string; }; const client = createSearchClient({ search: (requests) => Promise.resolve( createMultiSearchResponse( ...requests.map((request) => createSingleSearchResponse({ hits: [ { objectID: '1', somethingSpecial: 'a' }, { objectID: '2', somethingSpecial: 'b' }, { objectID: '3', somethingSpecial: 'c' }, ], index: request.indexName, }) ) ) ), }); const { container } = render( hitComponent={({ hit }) => ( {`${hit.__position} - ${hit.somethingSpecial}`} )} /> ); await waitFor(() => { expect(container.querySelectorAll('strong')).toHaveLength(3); expect(container.querySelector('.ais-Hits')).toMatchInlineSnapshot(`
  1. 1 - a
  2. 2 - b
  3. 3 - c
`); }); }); test('forwards custom class names and `div` props to the root element', () => { const { container } = render( ); const root = container.firstChild; expect(root).toHaveClass('MyHits', 'ROOT'); expect(root).toHaveAttribute('aria-hidden', 'true'); }); });