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