0

我正在尝试使用 Jasmine Karma 测试以下代码。但是如何在里面模拟链式方法$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' )
    );
}

我正在尝试的测试代码是:

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

});

4

0 回答 0