angular / angular.js

AngularJS - HTML enhanced for web apps!
https://angularjs.org
MIT License
58.8k stars 27.48k forks source link

Testing docs don't have info about angular spying #11067

Open ilanbiala opened 9 years ago

ilanbiala commented 9 years ago

I can't find any information about how to make sure methods are called in Angular-specific code via Jasmine spies. I've looked at the angular-seed, the unit and E2E test pages on angularjs.org, and in various other places, but they all have a different setup and most seem to fail now when actually trying them out.

Narretz commented 9 years ago

Can you describe / give an example of what you want to achieve?

ilanbiala commented 9 years ago

I'm trying to spy on a service method being called once something has happened in my controller, but every guide I have followed doesn't seem to work.

Narretz commented 9 years ago

Testing with spies isn't really exclusive to angular, but it's probably a good idea to mention this. If you could break down your code into small pieces and post it here, I'll have look.

ilanbiala commented 9 years ago

@Narretz this is one test where I can't seem to get the spy working.

$httpBackend
  .expectPOST('/api/users/hasAccount')
  .respond({
    hasAccount: true,
    pending: true
  });

spyOn(MessageService, 'showFailureNotification').and.callThrough();

$scope.email = 'ibiala@ctemc.org';
$scope.authenticateOrRequestInvite();

expect(MessageService.showFailureNotification).toHaveBeenCalled();