3
我使用elasticsearch并想编写一个单元测试下面的代码:如何模拟Node.js中的elasticsearch实例?
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);
});
}
我所熟悉的摩卡和兴农,但是我不知道一个好的模式来使用存根\模拟client.create
在这种情况下。
任何人都可以提出一种方法,我可以使用?
作为参考:我结束了以下这样的事情:https://slmyers.github.io/elasticsearch/javascript/testing/2 017/04/04 /嘲讽-elasticsearch-calls.html。可能与您的方法有所不同,具体取决于实施。 – blo0p3r