Open seantalbot-jisc opened 3 years ago
I'm using
"@elastic/elasticsearch-mock": "0.3.0",
"@elastic/elasticsearch": "7.9.1",
in case that helps.
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.
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.
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
Hi, thanks for this excellent library.
I'm trying to mock specific
ResponseError
s in TypeScript but I'm getting stuck. TheResponseError
constructor takes a huge amount of arguments that I'm unable to workaround without the compiler complaining or it not working.This is as far as I've got:
I had previously set
connection
to{} as Connection
but I received no response in my test, so I thought I could use the one fromClientMock.getConnection()
instead. However, I get an error:Any suggestions?