{"repo":"elastic/elasticsearch-js-mock","free":true,"listed":false,"github":"https://github.com/elastic/elasticsearch-js-mock","clone":"git clone https://github.com/elastic/elasticsearch-js-mock.git","description":"Mock utility for the Elasticsearch's Node.js client","language":"JavaScript","stars":50,"topics":["elasticsearch","nodejs","client","rest","mock","testing-tools"],"license":"Apache-2.0","category":"dev-tools","readme_excerpt":"Elasticsearch Node.js client mock utility When testing your application you don't always need to have an Elasticsearch instance up and running, but you might still need to use the client for fetching some data. If you are facing this situation, this library is what you need. Use v1.0.0 for @elastic/elasticsearch ≤ v7 compatibility and v2.0.0 for @elastic/elasticsearch ≥ v8 compatibility. Features - Simple and intuitive API - Mocks only the http layer, leaving the rest of the client working as usual - Maximum flexibility thanks to \"strict\" or \"loose\" mocks Install Usage API Constructor Before start using the library you need to create a new instance: add Adds a new mock for a given pattern and assigns it to a resolver function. You can also specify multiple methods and/or paths at the same time: get Returns the matching resolver function for the given pattern, it returns null if there is not a matching pattern. clear Clears/removes mocks for specific route(s). clearAll Clears all mocks. getConnection Returns a custom Connection class that you must pass to the Elasticsearch client instance. Mock patterns A pattern is an object that describes an http query to Elasticsearch, and it looks like this: The more field you specify, the more the mock will be strict, for example: You can craft custom responses for different queries: You can also specify dynamic urls: Wildcards are supported as well. Dynamic responses The resolver function takes a single parameter which represent the API ","default_branch":null,"files":null,"tree":[],"storefront":"/r/elastic","claimed":false,"request_supported":{"post":"https://gitbuyer.com/r/elastic/elasticsearch-js-mock/request-supported","requests":0},"note":"indexed from public GitHub; nothing is for sale on this page. Clone it from GitHub. Paid listings live at /search."}