小编Tre*_*res的帖子

Angular mock $ httpBackend给出没有待处理的请求

按照angularJS $ httpBackend的官方指南,我会做这个测试,但是Karma给我这个错误: Error: No pending request to flush ! at Function.$httpBackend.flush

测试

'use strict';

describe('profileCtrl', function () {
var scope, $httpBackend;

beforeEach(angular.mock.module('maap'));
beforeEach(angular.mock.inject(function($rootScope, $controller, _$httpBackend_){

    $httpBackend = _$httpBackend_;
    $httpBackend.when('GET', 'profile').respond([{id: 1, name: 'Bob'}]);
    scope = $rootScope.$new();
    $controller('profileCtrl', {$scope: scope});
}))

it('should fetch list of users', function(){
    $httpBackend.flush();
    expectGET(scope.current_user.length).toBe(1);
    expect(scope.current_user[0].name).toBe('Bob');
});
Run Code Online (Sandbox Code Playgroud)

});

这个简单的控制器:

'use strict';

 angular.module('maap').controller('profileCtrl', function($scope, UserService) {

$scope.current_user = UserService.details(0);
Run Code Online (Sandbox Code Playgroud)

});

angularjs karma-jasmine

19
推荐指数
2
解决办法
3万
查看次数

Angularjs,等待嵌套的承诺

我有3个服务返回3个promise,但第三个需要第二个数据,所以我把它称为第二个.我想等待所有三个承诺得到解决,这是我实现的方式,但不起作用(仅等待第一个和第二个).

var promise1, promise2, promise3;

promise1 = service1();
promise2 = service2();

promise2.then(function (data) {
  promise3= service3(data);

});

$q.all([ promise1, promise2, promise3]).then(function success() {
 //somehing
});
Run Code Online (Sandbox Code Playgroud)

javascript angularjs q angular-promise

7
推荐指数
1
解决办法
4673
查看次数

Heroku,node.js,服务器崩溃错误:大多数中间件(如logger)不再与Express捆绑在一起,必须单独安装

我尝试将我的应用程序部署到heroku服务中,但在推送文件后,日志会给我这个错误:错误:大多数中间件(如logger)不再与Express捆绑在一起,必须单独安装.

我的package.json是

{
   "dependencies":{
      "connect":"3.0.0-rc.2",
      "express":"^4.1.1",
      "express-logger":"0.0.2",
      "gzippo":"^0.2.0",
      "logfmt":"^1.1.2"
   },
   "devDependencies":{
      "connect":"3.0.0-rc.2",
      "grunt":"~0.4.1",
      "grunt-autoprefixer":"~0.4.0",
      "grunt-bower-install":"~1.0.0",
      "grunt-concurrent":"~0.5.0",
      "grunt-contrib-clean":"~0.5.0",
      "grunt-contrib-compass":"~0.7.2",
      "grunt-contrib-concat":"~0.3.0",
      "grunt-contrib-connect":"~0.5.0",
      "grunt-contrib-copy":"~0.4.1",
      "grunt-contrib-cssmin":"~0.7.0",
      "grunt-contrib-htmlmin":"~0.1.3",
      "grunt-contrib-imagemin":"~0.3.0",
      "grunt-contrib-jshint":"~0.7.1",
      "grunt-contrib-uglify":"~0.2.0",
      "grunt-contrib-watch":"~0.5.2",
      "grunt-google-cdn":"~0.2.0",
      "grunt-karma":"^0.8.3",
      "grunt-newer":"~0.6.1",
      "grunt-ngmin":"~0.0.2",
      "grunt-rev":"~0.1.0",
      "grunt-svgmin":"~0.2.0",
      "grunt-usemin":"~2.0.0",
      "jshint-stylish":"~0.1.3",
      "karma":"^0.12.14",
      "karma-jasmine":"^0.1.5",
      "karma-ng-html2js-preprocessor":"^0.1.0",
      "karma-ng-scenario":"^0.1.0",
      "load-grunt-tasks":"~0.4.0",
      "time-grunt":"~0.2.1"
   },
   "engines":{
      "node":">=0.10.0"
   },
   "name":"eversnap",
   "scripts":{
      "test":"grunt test"
   },
   "version":"0.0.1"
}
Run Code Online (Sandbox Code Playgroud)

heroku node.js express

2
推荐指数
1
解决办法
7177
查看次数