I have been attempting to perform a simple HTTP post in a unit test using Jasmine, but unfortunately, it is not functioning as expected. The application operates smoothly on the web, and I have individually tested various functions, all of which work seamlessly. However, this specific function refuses to cooperate.
describe('Service: Auth',function(){
beforeEach(function () {
module('ui.router');
module('main');
module('users');
});
var AuthFactory, httpBackend;
beforeEach(inject(function($httpBackend, _AuthFactory_) {
httpBackend = $httpBackend;
AuthFactory = _AuthFactory_;
}));
it('should return POST', function() {
AuthFactory.signIn({inputUser: {username: "admin"}, passInput: {password: "adminpass"}}).then(
function(result) {
console.log('======== SUCCESS ========');
console.log(result);
},
function(err) {
console.log('======== ERROR ========');
console.log(err);
},
function(progress) {
console.log('======== PROGRESS ========');
console.log(progress);
}
);
console.log('HTTP call finished.');
expect(1).toBe(1);
});
});
and here lies the factory:
angular.module('users').factory('AuthFactory', ['$http', function($http) {
var AuthFactory = {};
AuthFactory.signIn = function(data) {
return $http.post('http://127.0.0.1:3000/api/AuthFactoryServ/signIn', data);
};
AuthFactory.signOut = function(data) {
return $http.post('http://127.0.0.1:3000/api/AuthFactoryServ/signOut', data);
};
return AuthFactory;
}]);
This is what I am encountering:
PhantomJS 1.9.8 (Windows 7 0.0.0): Executed 0 of 1 SUCCESS (0 s
LOG: Object{$$state: Object{status: 0}, success: function (fn)
{ ... }, error: function (fn) { ... }}
PhantomJS 1.9.8 (Windows 7 0.0.0): Executed 0 of 1 SUCCESS (0 s
LOG: 'HTTP call finished.'
PhantomJS 1.9.8 (Windows 7 0.0.0): Executed 0 of 1 SUCCESS (0 s
PhantomJS 1.9.8 (Windows 7 0.0.0): Executed 1 of 1 SUCCESS (0 s
PhantomJS 1.9.8 (Windows 7 0.0.0): Executed 1 of 1 SUCCESS (0 secs / 0.022 secs)
I have verified that the HTTP calls function properly via Postman and return the expected data. So, where might I be erring?
Many thanks.