当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - How to test chained method in Jasmine Karma

问题描述:

I am trying to test the below piece of code with Jasmine Karma.

But how to mock chained method inside $mdDialog.show()?

// Actual code that need to be test.

this.showAlert = function ( error ) {

console.log("dfsfs");

$mdDialog.show(

$mdDialog.alert()

.clickOutsideToClose( true )

.title( 'Error' )

.textContent( error )

.ok( 'OK' )

);

}

The test code I'm trying is:

describe('Testing showAlert()', function(){

it('should exist',function(){

expect(ErrorHandler.showAlert).toBeDefined();

});

it('should open the alert dialog',function(){

var message="Some message";

ErrorHandler.showAlert(message);

expect(ErrorHandler.showAlert).toHaveBeenCalledWith(messa‌​ge);

});

});

分享给朋友:
您可能感兴趣的文章:
随机阅读: