likeastore / ngDialog

Modals and popups provider for Angular.js applications
http://likeastore.github.io/ngDialog
3.14k stars 692 forks source link

How to call ngDialog.open() from Jasmine unit test #503

Closed guylhermetabosa closed 7 years ago

guylhermetabosa commented 8 years ago

I'm using ngDialog v0.6.2 to display some info and get some actions from users, and I make a call to ngDialog from my controller, and I would like to test this scenario.

In my Controller I have this:

ngDialog.open({ template: 'modalOverrideCardId',  className: 'ngdialog-theme-plain' })                                          .then(function() {
 objectForRequest.sobrescrever = true;
 createCard(objectForRequest);
 }, function() {
// do something.
});

I'm making a call to my service, and based on the status code of the response I call this code above.

However, I would like to make this interaction without using protractor at least so far, and I want to be able to get the confirm() function from Jasmine for coverage reasons.

My Spec:

it('Deve conflitar na criaçao de um cartão', inject(function(CartaoConsumoService, $timeout, $compile, $document) {

            spy(ngDialog, 'openConfirm').and.callThrough();

            httpBackend.whenGET('modalOverrideCardId').respond(200);
            httpBackend.whenPOST(API_URL.cartoesConsumoUrl).respond(409);

            controller.createCard(obj);
            httpBackend.flush();

            ngDialog.openConfirm('modalOverrideCardId');
// Here is where i'm stuck
        }));
guylhermetabosa commented 7 years ago

Solved.

lidonis commented 7 years ago

@guylhermetabosa Can you post your solution please ?