2015-09-18 41 views
4

我正在尝试在Mean.js中开发一个项目。我已经安装了MEAN.JS并开始开发工作。但是在做npm测试之后,我面临一个问题。问题出现在登录部分。任何人都可以帮助我吗? 下面我提供的代码在mean.js项目中运行npm测试时出错

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: '[email protected]', token: {logintoken: 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9'}, isadmin: false, status:false}); 
      scope.signin(); 
      $httpBackend.flush(); 

      // Test scope value 
      expect(scope.authentication.user).toEqual('[email protected]'); 
      expect($cookieStore.get('token')).toBe('Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9'); 
      expect($location.url()).toEqual('/loading'); 
     }); 

的下面提供的,我得到运行在终端

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) 
+0

内联您的模板:http://stackoverflow.com/a/18368287/526973 – Lee

回答

3

NPM测试而这万阿英,蒋达清可以通过添加

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

要解决的错误触发登录功能后

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: '[email protected]', 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('[email protected]'); 
     expect($cookieStore.get('token')).toBe('Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9'); 
     expect($location.url()).toEqual('/loading'); 
    });