4

I am trying to develop a project in Mean.js. I have installed MEAN.JS and started working on the development. But after doing the npm test I am facing an issue. The issue is on signin part. Could anyone please help me on this? Below I am providing the code

    it('$scope.signin() should login with a correct user and password as user', function () {

           // Test expected GET request
           $httpBackend.when('POST', '/auth/signin').respond(200, {user: 'chinjubridgit.thomas@gmail.com', token: {logintoken: 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9'}, isadmin: false, status:false});
           scope.signin();
           $httpBackend.flush();

           // Test scope value
           expect(scope.authentication.user).toEqual('chinjubridgit.thomas@gmail.com');
           expect($cookieStore.get('token')).toBe('Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9');
           expect($location.url()).toEqual('/loading');
       });

The below provided is the error which I get while running npm test in terminal

    PhantomJS 1.9.8 (Linux 0.0.0) AuthenticationController $scope.signin() should login with a correct user and password as user FAILED
    Error: Unexpected request: GET modules/admins/views/admin/home-admin.client.view.html
    No more request expected at $httpBackend (/home/dev241/projects/mean/yourcause/public/lib/angular-mocks/angular-mocks.js:1181)
    at sendReq (/home/dev241/projects/mean/yourcause/public/lib/angular/angular.js:8427)
    at /home/dev241/projects/mean/yourcause/public/lib/angular/angular.js:8146
    at /home/dev241/projects/mean/yourcause/public/lib/angular/angular.js:11682
    at /home/dev241/projects/mean/yourcause/public/lib/angular/angular.js:11768
    at /home/dev241/projects/mean/yourcause/public/lib/angular/angular.js:12811
    at /home/dev241/projects/mean/yourcause/public/lib/angular/angular.js:12623
    at /home/dev241/projects/mean/yourcause/public/lib/angular-mocks/angular-mocks.js:1454
    at /home/dev241/projects/mean/yourcause/public/modules/users/tests/authentication.client.controller.test.js:72
    at /home/dev241/projects/mean/yourcause/node_modules/karma-jasmine/lib/boot.js:126
    at /home/dev241/projects/mean/yourcause/node_modules/karma-jasmine/lib/adapter.js:171
    at http://localhost:9876/karma.js:182
    at http://localhost:9876/context.html:175
    PhantomJS 1.9.8 (Linux 0.0.0): Executed 11 of 11 (1 FAILED) (0.011 secs / 0.172 secs)
Anoyz
  • 7,431
  • 3
  • 30
  • 35
Bridgit Thomas
  • 343
  • 2
  • 14

1 Answers1

3

This probelm can be solved by adding

    $httpBackend.when('GET', /\.html$/).respond('');    

after triggering the sign in function

it('$scope.signin() should login with a correct user and password as user', function () {

       // Test expected GET request
       $httpBackend.when('POST', '/auth/signin').respond(200, {user: 'chinjubridgit.thomas@gmail.com', token: {logintoken: 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9'}, isadmin: false, status:false});
       scope.signin();
       $httpBackend.when('GET', /\.html$/).respond('');  
       $httpBackend.flush();

       // Test scope value
       expect(scope.authentication.user).toEqual('jenson.raby@cubettech.com');
       expect($cookieStore.get('token')).toBe('Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9');
       expect($location.url()).toEqual('/loading');
   });
Jenson Raby
  • 769
  • 2
  • 6
  • 26