2017-08-10 102 views
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); 
    }); 
    }); 

回答