我想使用nodeJs查询elasticsearch的stats。
下面是我的源代码
const {Client} = require('@elastic/elasticsearch');
client = new Client({
Connection:'appropriate aws connection',
node:'some url',
agent:{
keepalive:,
maxsocket:,
maxfreesocket:
}
})
const stats = await client.nodes.stats();
console.log(stats);
// some operation on stats
字符串
我如何模仿这个elasticsearch方法?
我试过以下,但它无法模拟stats()
。
let sandbox = sinon.createSandbox();
before(()=>{
sandbox.stub(Client.prototype,'nodes').get(()=>{
stats: ()=>{
return dymmydata;
}
//where dummydata is already hardcoded
})
})
型
我哪里做错了?
1条答案
按热度按时间ffdz8vbo1#
让我们看看
nodes
API是如何定义的。参见/v8.8.1/src/api/index.ts#L401,您会发现nodes
API是由Object.defineProperties
通过getter函数定义的。字符串
我们应该使用
stub.get(getterFn)
API来替换这个存根的新getter。例如:
index.js
:型
index.test.js
:型