Sasindu H
Sasindu H

Reputation: 1578

How to test javascript Promise function in jasmine

this.result = new Promise( function( resolve, reject ){
   self.resolveMethod = resolve;
   self.rejectMethod = reject;
});

How can I test resolveMethod and rejectMethod are functions? Thanks

Upvotes: 2

Views: 121

Answers (3)

Sasindu H
Sasindu H

Reputation: 1578

This is working for me

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) );
    });       
});

Upvotes: 0

Pedro Vaz
Pedro Vaz

Reputation: 820

You could try something like:

expect(type(result.resolveMethod).toBe('function');
expect(type(result.rejectMethod).toBe('function');

Upvotes: 0

Herr Derb
Herr Derb

Reputation: 5357

Use this helper method and assert.

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

Upvotes: 2

Related Questions