what is the code to be used to pass the service call test using jasmine.js
the code below is my angular.js service call
var myApp = angular.module('myApp',[]);
app.controller('Myctrl', function($scope, $http) {
$http.get("http://ift.tt/1aaNO8P")
.success(function(response) {$scope.names = response.records;});
});
can you provide me with the relevant code to pass the unit test using jasmine.js i tried so many codes and methods but still i am getting severak issues and eventhough i did the needful i wont recover what is the code to used for the unit test of the above angular service call using jasmine.js
this is the code that i tried so far
describe('Myctrl', function() {
var $httpBackend, scope, createController, authRequestHandler;
// Set up the module
beforeEach(module('myApp'));
alert("Hello there!");
beforeEach(inject(function ($injector) {
// Set up the mock http service responses
alert("Hello there!");
$httpBackend = $injector.get('$httpBackend');
// backend definition common for all tests
alert("Hello there!");
authRequestHandler = $httpBackend.whenGET('GET', 'http://ift.tt/1aaNO8P')
.respond(true);
// Get hold of a scope (i.e. the root scope)
$rootScope = $injector.get('$rootScope');
// The $controller service is used to create instances of controllers
var $controller = $injector.get('$controller');
createController = function() {
return $controller('Myctrl', {'$scope' : scope});
};
})
);
/*
afterEach(function () {
$httpBackend.verifyNoOutstandingExpectation();
$httpBackend.verifyNoOutstandingRequest();
});
*/
it('should fetch authentication token', function() {
//create expectation
$httpBackend.expectGET('GET','http://ift.tt/1aaNO8P')
var controller = createController()
$httpBackend.flush();
expect(scope.names).toBeTruthy(true);
});
});
Aucun commentaire:
Enregistrer un commentaire