0
我有以下函數使用bind
將上下文綁定到then
鏈。當我嘗試和測試,它拋出單元測試藍鳥promise綁定函數
TypeError: redisClient.hgetallAsync(...).bind is not a function
myFunc() {
let self = this;
return redisClient.hgetallAsync('abcde')
.bind({ api: self })
.then(doStuff)
.catch(err => {
// error
});
}
測試
let redisClient = { hgetallAsync: sinon.stub() };
describe('myFunc',() => {
beforeEach(() => {
redisCLient.hgetallAsync.resolves('content!');
});
it('should do stuff',() => {
return myFunc()
.should.eventually.be.rejectedWith('Internal Server Error')
.and.be.an.instanceOf(Error)
.and.have.property('statusCode', 500);
});
});