Created
August 18, 2015 18:57
-
-
Save NicholasBoll/0ca7d14d4216498418ed to your computer and use it in GitHub Desktop.
Async AngularJS testing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe('getFormattedCustomerInfo-async', function(){ | |
var customerService; | |
var customerFormattingService; | |
var $q; | |
var $scope; | |
beforeEach(function(){ | |
module('customer'); | |
inject( function($injector){ | |
customerService = $injector.get('customer-service'); | |
customerFormattingService = $injector.get('customer-formatting-service-async'); | |
$q = $injector.get('$q'); | |
$scope = $injector.get('$rootScope').$new(); | |
}); | |
}); | |
it('should return formatted customer information based on async call', function(){ | |
spyOn(customerService,['getCustomerById']).and.returnValue($q.when({firstName:'Joe',lastName:'Smith',totalSales:50})); | |
var formatted; | |
customerFormattingService.getFormattedCustomerInfo(1).then(function(_formatted){ | |
formatted = _formatted | |
}); | |
$scope.$apply(); | |
expect(customerService.getCustomerById).toHaveBeenCalledWith(1); | |
expect(formatted).toBe('Joe Smith Total Sales: $50'); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment