Mock JS client for Instantsearch UI Intergration testing

I was wondering if any has tried writing a mock algoliasearch client to feed into the <InstantSearch /> component (or other Instant Search implementation) that avoids the API and is suitable for integration testing. I’m kinda going along the Kent C. Dodds “make your tests resemble actual software uses cases” idea and figure mocking the client is easier and makes more sense then mocking say the InstantSearch provider.

Hi there,

We don’t provide an official mock for algoliasearch. However it’s pretty trivial to write a mock with jest, we are actually doing it for some internal projects.

If you are doing UI test it’s a bit more complicated as you are not in a unit testing env.
But If you are using the new AlgoliaSearchJS client (v4 at the time of writing), you can simply override the http Requested by your own and return the data appropriate for your tests.

I hope it helps,
Best Regards

1 Like