UNPKG

quickmock

Version:

quickmock is an simple service for automatically injecting mocks into your AngularJS unit tests using Jasmine

60 lines (50 loc) 2.05 kB
(function(){ describe('NotificationService', function () { var notificationService, fakeMessage, mockWindow, titles; beforeAll(function(){ notificationService = quickmock({ providerName: 'NotificationService', moduleName: 'QuickMockDemo', mockModules: ['QuickMockDemoMocks'] }); fakeMessage = 'some fake message'; mockWindow = notificationService.$mocks.$window; titles = notificationService.$mocks.NotificationTitles; }); it('should display proper error message', function(){ notificationService.error(fakeMessage); var messageShown = mockWindow.alert.calls.mostRecent().args[0]; expect(messageShown).toContain(titles.error); expect(messageShown).toContain(fakeMessage); }); it('should display proper success message', function(){ notificationService.success(fakeMessage); var messageShown = mockWindow.alert.calls.mostRecent().args[0]; expect(messageShown).toContain(titles.success); expect(messageShown).toContain(fakeMessage); }); it('should display proper warning message', function(){ notificationService.warning(fakeMessage); var messageShown = mockWindow.alert.calls.mostRecent().args[0]; expect(messageShown).toContain(titles.warning); expect(messageShown).toContain(fakeMessage); }); it('should display proper basic message', function(){ notificationService.basic(fakeMessage); var messageShown = mockWindow.alert.calls.mostRecent().args[0]; expect(messageShown).toContain(titles.basic); expect(messageShown).toContain(fakeMessage); }); it('should display proper confirmation message', function(){ notificationService.confirm(fakeMessage); var messageShown = mockWindow.confirm.calls.mostRecent().args[0]; expect(messageShown).toContain(titles.confirm); expect(messageShown).toContain(fakeMessage); }); it('should return confirmed response from user', function(){ mockWindow.confirm.and.returnValue(0); var result = notificationService.confirm(fakeMessage); expect(result).toEqual(0); }); }); })();