【问题标题】: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]';
      }
      

      【讨论】:

        猜你喜欢
        • 2019-06-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-01-24
        • 2016-12-18
        • 2013-11-12
        • 1970-01-01
        相关资源
        最近更新 更多