elasticsearch-js-mock icon indicating copy to clipboard operation
elasticsearch-js-mock copied to clipboard

How to use elastic-mock properly?

Open Artem-Tsymbal opened this issue 3 years ago • 4 comments

"@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 avatar Apr 19 '22 13:04 Artem-Tsymbal

Hello, could anybody help me to solve my error

Artem-Tsymbal avatar Apr 19 '22 13:04 Artem-Tsymbal

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

XOlvl9lK avatar Jul 13 '22 08:07 XOlvl9lK

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.

wangdrew avatar Dec 01 '22 00:12 wangdrew

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

dimas-cyriaco avatar Feb 08 '24 18:02 dimas-cyriaco