Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function() {
- var loginMod = angular.module("loginMod", []);
- var loginService = function($http, $httpParamSerializerJQLike) {
- var token = null;
- var getToken = function(username, password) {
- var creds = {
- username: username,
- password: password
- };
- return $http({
- url: "<<some https url>>",
- method: "POST",
- data: $httpParamSerializerJQLike(creds)
- }).then(function(response, status, headers) {
- return response.data;
- })
- };
- return {
- getToken: getToken,
- token: token,
- };
- };
- loginMod.factory("loginService", loginService);
- }());
- describe('loginService', function() {
- beforeEach(module('loginMod'));
- beforeEach(inject(function(_loginService_, _$httpBackend_) {
- service = _loginService_;
- $httpBackend = _$httpBackend_;
- }));
- it('should invoke service with right parameters', function() {
- $httpBackend.expectPOST('<<some https url>>', {
- "username" : "xxxxx",
- "password" : "yyyyy"
- }).respond({});
- service.getToken('xxxxx', 'yyyy');
- $httpBackend.flush();
- });
- });
- INFO [Chrome 51.0.2704 XXXXX]: Connected on socket ojoou3CV6uVSuPZx2E3D with id 84159242
- Chrome 51.0.2704 (XXXX) loginService should invoke service with right parameters FAILED
- SyntaxError: Unexpected token p in JSON at position 0
- at Object.parse (native)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement