elastic / elasticsearch-js-mock

Mock utility for the Elasticsearch's Node.js client
https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/client-testing.html
Apache License 2.0
47 stars 13 forks source link

How to use elastic-mock properly? #26

Open Artem-Tsymbal opened 2 years ago

Artem-Tsymbal commented 2 years ago

"@elastic/elasticsearch": "^8.1.0", "@elastic/elasticsearch-mock": "^2.0.0", "jest": "^24.9.0", Node: v12.22.7

image

console.log(mock.getConnection()) -> [class MockConnection extends BaseConnection]

console.error node_modules/jest-jasmine2/build/jasmine/Env.js:289
    Unhandled error

  console.error node_modules/jest-jasmine2/build/jasmine/Env.js:290
    ResponseError: {"error":"Mock not found"}
        at SniffingTransport.request (.../node_modules/@elastic/transport/src/Transport.ts:532:17)
        at Indices.delete (.../node_modules/@elastic/elasticsearch/src/api/api/indices.ts:301:12)
Artem-Tsymbal commented 2 years ago

Hello, could anybody help me to solve my error

XOlvl9lK commented 2 years ago

I have the same problem {"error":"Mock not found"}

wangdrew commented 1 year ago

I also got {"error":"Mock not found"} because the mock received a request that doesn't match any resolver function that I set up. In my case, I didn't pay close attention to the fact that my application code was hitting ElasticSearch with a POST request and I had set up the mock resolver with method: 'GET' like in the code examples.

dimas-cyriaco commented 8 months ago

It would be nice for this error to show what request was made. This way we could more easily create the correct handler.