【问题标题】:How to test javascript Promise function in jasmine如何在 jasmine 中测试 javascript Promise 函数
【发布时间】:2017-01-16 04:59:34
【问题描述】:
this.result = new Promise( function( resolve, reject ){
self.resolveMethod = resolve;
self.rejectMethod = reject;
});
如何测试 resolveMethod 和 rejectMethod 是函数?谢谢
【问题讨论】:
标签:
javascript
unit-testing
testing
jasmine
【解决方案1】:
这对我有用
describe('result', function() {
it('should assign resolve function to resolveMethod', function() {
expect( instance.resolveMethod ).toEqual( jasmine.any(Function) );
});
it('should assign reject function to rejectMethod', function() {
expect( instance.rejectMethod ).toEqual( jasmine.any(Function) );
});
});
【解决方案2】:
你可以试试这样的:
expect(type(result.resolveMethod).toBe('function');
expect(type(result.rejectMethod).toBe('function');
【解决方案3】:
使用这个辅助方法并断言。
function isFunctionA(object) {
return object && getClass.call(object) == '[object Function]';
}