I am just starting to understand Angularjs and plan to create an application. I am really a PHP programmer and have a little background in javascript. Angularjs was introduced to me by a friend. I was warned that I should also study its testing of Jasmine / karma before the functionality of the application becomes larger. So, at the moment I have a message in http format that sends an email and password, which, if successful, will return the token. Basically, if success redirects the user to the user / profile page
Controller Code:
function MainCtrl($scope, $location, Api, localStorageService, Security) { $scope.loginUser = function () { Api.authenticatePlayer({ email : $scope.main.email, password : $scope.main.password }).then(function (result){
And here is my testcript:
beforeEach(function() { module('myApp.services'), module("myApp.controllers") }); beforeEach(inject(function($controller, $rootScope, $location, Api, localStorageService, $httpBackend, Security) { this.$location = $location; this.$httpBackend = $httpBackend; this.scope = $rootScope.$new(); this.redirect = spyOn($location, 'path'); $controller("MainCtrl", { $scope : this.scope, $location : $location, localStorageService : localStorageService, Security : Security }); })); describe("successfully logging in", function () { it("should redirect you to /user/profile", function() {
Here is my service.js code:
return { authenticatePlayer: function(postData) { return $http({ method : 'POST', url : api + 'auth/player', data : postData, headers : {'Content-Type' : 'application/json'} }); } }
Failed to run test test :(. Here is the error:
Chrome 24.0 (Linux) controller: MainCtrl successfully logging in should redirect you to /user/profile FAILED Error: Unexpected request: POST http:
Someone can help. So sorry for the trouble though.