I am using elasticsearch and would like to write a unit test for the following code:
import * as elasticsearch from "elasticsearch";
import config from "../config";
const client = new elasticsearch.Client({
host: config.elasticsearch.host,
log: "trace"
});
export function index(data) {
return new Promise((resolve, reject) => {
client.create({
index: "myindex",
type: "mytype",
id: booking.urn,
body: data
}).then(resolve, reject);
});
}
I am familiar with mocha and sinon, however I don't know of a good pattern to use to stub\mock client.create in this case.
Can anyone suggest an approach that I could use?