File size: 1,197 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { render } from '@testing-library/react';
import React from 'react';
import { InstantSearch as InstantSearchCore } from 'react-instantsearch-core';

import { createSearchClient } from '../../../../test/mock';
import { useSearchBox } from '../connectors/useSearchBox';
import { noop } from '../lib/noop';

function SearchBox() {
  useSearchBox({});

  return null;
}

describe('Compat', () => {
  test('throws when using hooks with React InstantSearch Core Provider', () => {
    // Hide the errors from the test logs.
    jest.spyOn(console, 'error').mockImplementation(noop);

    const searchClient = createSearchClient({});

    expect(() => {
      render(
        <InstantSearchCore indexName="indexName" searchClient={searchClient}>
          <SearchBox />
        </InstantSearchCore>
      );
    }).toThrowErrorMatchingInlineSnapshot(`
      "[InstantSearch] Hooks must be used inside the <InstantSearch> component.

      They are not compatible with the \`react-instantsearch-core\` and \`react-instantsearch-dom\` packages, so make sure to use the <InstantSearch> component from \`react-instantsearch-hooks\`."
    `);

    jest.spyOn(console, 'error').mockRestore();
  });
});