mercredi 4 mai 2016

Unable to test a method using Jasmine

How to test the return value of dialog.button in Jasmine?

angular.module('employer').factory($window) {
  dialog.button = function(){
    $window.location.href = 'tel:' + dialog.number;
    return $window.location.href;
  };
};

I have tried the following unit tests in Jasmine with no luck,

1)

it('should check for a value', function(){
  spyOn(dialog, 'button');
  expect(dialog.button).toEqual('tel:' + dialog.clientNumber);
});

Console Error: Expected spy on button to equal 'tel:1234566789'.

2)

it('should check for a value', function(){
      spyOn(dialog, 'button');
      expect(dialog.button()).toEqual('tel:' + dialog.clientNumber);
    });

Console Error: Expected undefined to equal 'tel:1234566789'.

What am I doing wrong?

Aucun commentaire:

Enregistrer un commentaire