I have spent way too much time on this. I have a simple angular app that gets some JSONP from a remote server and displays that on the screen.
I am having the hardest time creating a unit test for it with Jasmine.
Here is my App
var pdApp = angular.module('pdApp', []);
pdApp.controller('pdController', function ($scope, $http) {
var jsonpUrl = "http://10.1.20.377/products/1/167?cb=JSON_CALLBACK";
$http.jsonp(jsonpUrl).success(function(data) {
$scope.pageContent = data.pageContent;
$scope.cartContent = data.cartContent;
$scope.content = data.productContent;
});
});
And here is my unit test
describe('myTest', function () {
var MainCtrl, scope, httpBackend;
beforeEach(module('pdApp'));
module('pdApp', function($provide) {
$provide.value('DefaultContent', defaultJSON);
});
beforeEach(inject(function($controller, $rootScope, $httpBackend) {
httpBackend = $httpBackend;
scope = $rootScope.$new();
MainCtrl = $controller('pdController', {
$scope: scope
});
}));
it("Product name should be set", function(){
httpBackend.whenJSONP("/products/1/167").respond(
{
"name" : "Prod Name",
"desc" : "Long Description Here"
}
);
expect(scope.pageContent.name).toEqual("Prod Name");
});
});