Giter Site home page Giter Site logo

Comments (2)

delvedor avatar delvedor commented on June 22, 2024 1

Hello! Currently, it's not possible, but it would be a nice feature!
It should be opt-in in my opinion, so if a user want to use a different mock method (jest.fn for example), they can do it.
Would you like to work on it? :)

from elasticsearch-js-mock.

iamEAP avatar iamEAP commented on June 22, 2024 1

For future wanderers who find themselves here: a trick I used to get this functionality is as follows:

const deleteSpy = jest.fn().mockReturnValue({});
mock.add({
  method: 'DELETE',
  path: '/some-specific-index-name',
}, deleteSpy);

await client.indices.delete({
  index: 'some-specific-index-name',
});

expect(deleteSpy).toHaveBeenCalled();

It's not great, because a failure doesn't make a distinction between "wasn't actually called at all" and "was called with the wrong index name." You could work around this by matching any index and asserting the shape of the call to the deleteSpy, but it's quite verbose.

Naturally, the same approach (of passing a spy with mock implementation as the response body getter) will work on any method/path.

from elasticsearch-js-mock.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.