【发布时间】:2017-06-27 09:32:27
【问题描述】:
我正在使用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);
});
}
我熟悉 mocha 和 sinon,但是我不知道在这种情况下用于 stub\mock client.create 的好模式。
谁能建议我可以使用的方法?
【问题讨论】:
-
作为一个仅供参考:我最终关注了这样的事情:slmyers.github.io/elasticsearch/javascript/testing/2017/04/04/…。根据实施情况,可能与您的方法有点不同。
标签: javascript node.js unit-testing tdd sinon