2016-09-08 43 views
2
this.result = new Promise(function(resolve, reject){ 
    self.resolveMethod = resolve; 
    self.rejectMethod = reject; 
}); 

如何測試resolveMethod和rejectMethod函數?謝謝如何在jasmine中測試javascript Promise函數

+0

的可能的複製[?如何我可以檢查是否一個JavaScript變量函數類型(HTTP ://stackoverflow.com/questions/5999998/how-can-i-check-if-a-javascript-variable-is-function-type) – Caramiriel

回答

0

這是爲我工作

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

使用此輔助方法並斷言。

function isFunctionA(object) { 
return object && getClass.call(object) == '[object Function]'; 
} 
0

你可以嘗試這樣的:

expect(type(result.resolveMethod).toBe('function'); 
expect(type(result.rejectMethod).toBe('function'); 
相關問題