加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – 在mean.js项目中运行npm test时出错

发布时间:2020-12-17 17:15:06 所属栏目:安全 来源:网络整理
导读:我正在尝试在Mean.js开发一个项目.我已经安装了MEAN.JS并开始进行开发.但在进行了npm测试后,我遇到了一个问题.问题出在登录部分.有人可以帮我这个吗? ?下面我提供的代码 it('$scope.signin() should login with a correct user and password as user',funct
我正在尝试在Mean.js开发一个项目.我已经安装了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: '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');
       });

下面提供的是我在终端中运行npm test时得到的错误

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)

解决方法

这个问题可以通过添加来解决

$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',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');
   });

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读