Advertisement
Guest User

Untitled

a guest
Jul 18th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. (function() {
  2.  
  3. var loginMod = angular.module("loginMod", []);
  4.  
  5. var loginService = function($http, $httpParamSerializerJQLike) {
  6.  
  7. var token = null;
  8.  
  9. var getToken = function(username, password) {
  10. var creds = {
  11. username: username,
  12. password: password
  13. };
  14.  
  15. return $http({
  16. url: "<<some https url>>",
  17. method: "POST",
  18. data: $httpParamSerializerJQLike(creds)
  19. }).then(function(response, status, headers) {
  20. return response.data;
  21. })
  22. };
  23.  
  24. return {
  25. getToken: getToken,
  26. token: token,
  27. };
  28. };
  29.  
  30. loginMod.factory("loginService", loginService);
  31. }());
  32.  
  33. describe('loginService', function() {
  34. beforeEach(module('loginMod'));
  35. beforeEach(inject(function(_loginService_, _$httpBackend_) {
  36. service = _loginService_;
  37. $httpBackend = _$httpBackend_;
  38. }));
  39.  
  40. it('should invoke service with right parameters', function() {
  41. $httpBackend.expectPOST('<<some https url>>', {
  42. "username" : "xxxxx",
  43. "password" : "yyyyy"
  44. }).respond({});
  45. service.getToken('xxxxx', 'yyyy');
  46. $httpBackend.flush();
  47. });
  48. });
  49.  
  50. INFO [Chrome 51.0.2704 XXXXX]: Connected on socket ojoou3CV6uVSuPZx2E3D with id 84159242
  51. Chrome 51.0.2704 (XXXX) loginService should invoke service with right parameters FAILED
  52. SyntaxError: Unexpected token p in JSON at position 0
  53. at Object.parse (native)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement