Giter Site home page Giter Site logo

Comments (4)

nesjett avatar nesjett commented on July 2, 2024 2

To me, this worked out:

      mock.add({ 
          method: 'POST', 
          path: `/my_index/_bulk`
      }, () => ( 
          new ResponseError({
              body: error,
              statusCode: 404,
              headers: {},
              meta: {} as any,
              warnings: [],
          })
      ));

Note: If you want to still return the "meta" prop, you can do the same strategy with the connection: connection: {} as any

Note2: "error" is a const defined earlier, with the desired content

from elasticsearch-js-mock.

seantalbot-jisc avatar seantalbot-jisc commented on July 2, 2024 1

In case it's helpful to others, I worked around this by manually crafting one:

const err = Object.create(ResponseError.prototype);
Object.assign(err, {
    meta: {
        body: {
            status: 500,
            error: {
                type: "whatever",
            },
        },
        500,
        headers: {},
    },
});

This means the object returns true to instanceof ResponseError in my exception handler code and works for my use case.

from elasticsearch-js-mock.

seantalbot-jisc avatar seantalbot-jisc commented on July 2, 2024

I'm using

"@elastic/elasticsearch-mock": "0.3.0",
"@elastic/elasticsearch": "7.9.1",

in case that helps.

from elasticsearch-js-mock.

rokumura7 avatar rokumura7 commented on July 2, 2024

I'm getting stuck too.
I'd like to use ResponseError to write tests for unexpected requests, but there is more code to generate ResponseError, in other words, the code for testing is getting mess.
I'd like to know if there is a better way to mock ResponseError.

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.