# Developer Guide: Angular Services: Testing Angular Services

Following is a unit test for the service in the example in Creating Angular Services. The unit test example uses Jasmine spy (mock) instead of a real browser alert.

    var mock, notify;

    beforeEach(function() {
      mock = {alert: jasmine.createSpy()};

      module(function($provide) {
        $provide.value('$window', mock);
      });

      inject(function($injector) {
        notify = $injector.get('notify');
      });
    });

    it('should not alert first two notifications', function() {
      notify('one');
      notify('two');

      expect(mock.alert).not.toHaveBeenCalled();
    });

    it('should alert all after third notification', function() {
      notify('one');
      notify('two');
      notify('three');

      expect(mock.alert).toHaveBeenCalledWith("one\ntwo\nthree");
    });

    it('should clear messages after alert', function() {
      notify('one');
      notify('two');
      notify('third');
      notify('more');
      notify('two');
      notify('third');

      expect(mock.alert.callCount).toEqual(2);
      expect(mock.alert.mostRecentCall.args).toEqual(["more\ntwo\nthird"]);
    });

### Related Topics

- Understanding Angular Services
- Creating Angular Services
- Managing Service Dependencies
- Injecting Services Into Conrollers

### Related API

- `Angular Service API`