小编Jon*_*ans的帖子

Jasmine测试promise.then函数

我尝试用Jasmine测试我的应用程序并遇到以下问题:
我将根据then我的承诺计算一些东西.这就是我需要测试代码的地方.

这是我的控制器的代码:

  TestCtrl.$inject = ["$scope", "TestService"];
  /* ngInject */
  function TestCtrl($scope, TestService) {
    $scope.loadData = function () {
      TestService.getData().then(function (response) {
        $scope.data = response.data;
        $scope.filtered = $scope.data.filter(function(item){
          if(item.id > 1000){
            return true;
          }
          return false;
        })
      });
    }
  }
Run Code Online (Sandbox Code Playgroud)

我的Jasmine测试代码:

describe('TestService tests', function () {
  var $q;
  beforeEach(function () {
    module('pilot.fw.user');
  });
  beforeEach(inject(function (_$q_) {
    $q = _$q_;
  }));
  describe('UserController Tests', function () {

    beforeEach(inject(function (_$httpBackend_, $rootScope, $controller) {
      this.scope = $rootScope.$new();
      this.$rootscope = $rootScope;
      this.$httpBackend = …
Run Code Online (Sandbox Code Playgroud)

javascript jasmine angularjs

32
推荐指数
3
解决办法
5万
查看次数

标签 统计

angularjs ×1

jasmine ×1

javascript ×1