Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/472.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript $urlRouterProvider创建$httpBackend错误_Javascript_Angularjs_Karma Runner_Httpbackend - Fatal编程技术网

Javascript $urlRouterProvider创建$httpBackend错误

Javascript $urlRouterProvider创建$httpBackend错误,javascript,angularjs,karma-runner,httpbackend,Javascript,Angularjs,Karma Runner,Httpbackend,我正在使用$httpBackend服务模拟服务测试的请求。然而,我开始在测试中发现错误,表明请求实际上是被提出的,而不是被嘲笑的。当我注释掉我在app config中提供的catch-all路由时,测试都通过了。有人能解释为什么会这样吗?下面是我的代码和错误 编辑 编辑以包含Whisher的代码段,但不确定我是否正确使用了它 describe('AssetManager', function() { var state, $httpBackend, AssetManager; // If t

我正在使用$httpBackend服务模拟服务测试的请求。然而,我开始在测试中发现错误,表明请求实际上是被提出的,而不是被嘲笑的。当我注释掉我在app config中提供的catch-all路由时,测试都通过了。有人能解释为什么会这样吗?下面是我的代码和错误

编辑 编辑以包含Whisher的代码段,但不确定我是否正确使用了它

describe('AssetManager', function() {

var state, $httpBackend, AssetManager;

// If the app isn't broken into smaller modules,
// we must load the entire app for each test
beforeEach(function() {
  module('us.assetManager');
  module('statemock');

  inject(function($state, _$httpBackend_, _AssetManager_) {
    state = $state;
    $httpBackend = _$httpBackend_;
    AssetManager = _AssetManager_;
  });

});

afterEach(function() {
  $httpBackend.verifyNoOutstandingExpectation();
  $httpBackend.verifyNoOutstandingRequest();
});

describe('#getSpendAccounts', function() {

  beforeEach(function() {
    $httpBackend.expectGET('http://localhost:3000/api/facebook/spend_accounts.json').respond([
      {email: 'me@unifiedsocial.com'}
    ]);
  });

  it('fetches the users Spend Accounts', function() {
    var result;

    state.expectTransitionTo('fbCustomAudiences');

    AssetManager.getSpendAccounts('facebook').then(function(data) {
      result = data;
    });

    $httpBackend.flush();

    expect(result.data[0].email).toBe('me@unifiedsocial.com');
  });

});
app.js

(function() {
  'use strict';

   angular
     .module('us.assetManager', ['ui.router'])
     .config(function ($stateProvider, $urlRouterProvider) {
       // catch all route
      $urlRouterProvider.otherwise('/facebook/custom_audiences');

  $stateProvider
    .state('fbCustomAudiences', {
      abstract: true,
      templateUrl: '/common/views/layout.html',
      controller: 'CustomAudiencesCtrl as audiences',
      data: {
        network: 'facebook'
      },
      resolve: {
        getSpendAccounts: function(AssetManager) {
          return AssetManager.getSpendAccounts('facebook');
        }
      }
    })
    .state('fbCustomAudiences.root', {
      url: '/facebook/custom_audiences',
      views: {
        'breadcrumbs': {
          templateUrl: 'facebook/views/breadcrumbs.html'
        },
        'sidebar': {
          templateUrl: 'facebook/views/sidebar.html'
        },
        'acctControls': {
          templateUrl: 'facebook/views/controls.html'
        },
        'table': {
          templateUrl: 'facebook/views/custom-audiences-table.html'
        }
      }
    })
    .state('fbCustomAudiences.spendAccount', {
      url: '/facebook/custom_audiences/:spendAccountId',
      views: {
        'breadcrumbs': {
          templateUrl: 'facebook/views/breadcrumbs.html'
        },
        'sidebar': {
          templateUrl: 'facebook/views/sidebar.html'
        },
        'acctControls': {
          templateUrl: 'facebook/views/controls.html'
        },
        'table': {
          templateUrl: 'facebook/views/custom-audiences-table.html'
        }
      },
      resolve: {
        getAdAccounts: function(getSpendAccounts, AssetManager, $stateParams) {
          var spendAccountId = parseInt($stateParams.spendAccountId);

          // set the selectedSpendAccount for the dropdown
          AssetManager.selectedSpendAccount = _.find(getSpendAccounts.data, function(spendAccount) {
            return spendAccount.id === spendAccountId;
          });

          return AssetManager.getAdAccounts('facebook', spendAccountId);
        }
      }
    })
    .state('fbCustomAudiences.spendAccount.adAccount', {
      url: '/:adAccountId',
      views: {
        'breadcrumbs': {
          templateUrl: 'facebook/views/breadcrumbs.html'
        },
        'sidebar': {
          templateUrl: 'facebook/views/sidebar.html'
        },
        'acctControls': {
          templateUrl: 'facebook/views/controls.html'
        },
        'table': {
          templateUrl: 'facebook/views/custom-audiences-table.html'
        }
      },
      resolve: {
        getCustomAudiences: function(getAdAccounts, AssetManager, $stateParams) {
          var adAccountId = parseInt($stateParams.adAccountId);

          // set the selectedAdAccount for the dropdown
          AssetManager.selectedAdAccount = _.find(getAdAccounts.data, function(adAccount) {
            return adAccount.id === adAccountId;
          });

          return AssetManager.getAudiencesSummaryData('facebook', adAccountId);
        }
      }
    })
  });
})();
(function() {
'use strict';

angular
  .module('us.assetManager')
  .factory('AssetManager', AssetManager);


AssetManager.$inject = ['$http', '$state'];

function AssetManager($http, $state) {

// domain for HTTP endpoints
// StackOverflow doesnt allow localhost so just wrote domain
var domain = 'http://domain:3000/api/';

var spendAccounts = [],
    adAccounts = [],
    audiencesSummaryData = [],
    selectedSpendAccount = {},
    selectedAdAccount = {},
    selectedAudience = {},
    placeholder = null;

var factory = {
  spendAccounts: spendAccounts,
  adAccounts: adAccounts,
  selectedSpendAccount: selectedSpendAccount,
  audiencesSummaryData: audiencesSummaryData,
  selectedAdAccount: selectedAdAccount,
  selectedAudience: selectedAudience,
  placeholder: placeholder,
  getSpendAccounts: getSpendAccounts,
  getAdAccounts: getAdAccounts,
  getAudiencesSummaryData: getAudiencesSummaryData,
  getAudience: getAudience,
  createAudience: createAudience,
  editAudience: editAudience,
  deleteAudience: deleteAudience,
  setSelectedSpendAccount: setSelectedSpendAccount,
  setSelectedAdAccount: setSelectedAdAccount,
  hasSelectedSpendAccount: hasSelectedSpendAccount,
  hasSelectedAdAccount: hasSelectedAdAccount,
  hasSelectedAccounts: hasSelectedAccounts,
  setPlaceholder: setPlaceHolder
};

return factory;

// all URLs will change domains

function getSpendAccounts(socialNetwork) {
  var url = domain + socialNetwork + '/spend_accounts.json',
      AssetManager = this;

  return $http.get(url)
    .success(function(data) {
      AssetManager.spendAccounts = data;
    })
    .error(function() {
      console.log('Could not retrieve Spend Accounts.');
    });
}

function getAdAccounts(socialNetwork, spendAccountId) {
  var url = domain + socialNetwork + '/ad_accounts/' + spendAccountId + '.json'
      AssetManager = this;

  return $http.get(url)
    .success(function(data) {
      AssetManager.adAccounts = data;
    })
    .error(function() {
      console.log('Could not retrieve Ad Accounts.');
    });
}

function getAudiencesSummaryData(socialNetwork, adAccountId) {
  var url = domain + socialNetwork + '/audiences_summary_data/' + adAccountId + '.json',
      AssetManager = this;

  return $http.get(url)
    .success(function(data) {
      AssetManager.audiencesSummaryData = data;
    })
    .error(function() {
      console.log('Could not retrieve Audiences summary data.');
    });
}

function getAudience(socialNetwork, adAccountId, audienceId) {
  var url = domain + socialNetwork + '/audience/' + adAccountId + '/' + audienceId + '.json',
      AssetManager = this;

  return $http.get(url)
    .success(function(data) {
      AssetManager.selectedAudience = data;
    })
    .error(function() {
      console.log('Could not retrieve Audience with id: ' + audienceId);
    });
}
(function() {
'use strict';

describe('AssetManager', function() {

var AssetManager, $httpBackend;

// If the app isn't broken into smaller modules,
// we must load the entire app for each test
beforeEach(function() {
  module('us.assetManager');

  inject(function(_$httpBackend_, _AssetManager_) {
    $httpBackend = _$httpBackend_;
    AssetManager = _AssetManager_
  });

});

afterEach(function() {
  $httpBackend.verifyNoOutstandingExpectation();
  $httpBackend.verifyNoOutstandingRequest();
});

describe('#getSpendAccounts', function() {

  beforeEach(function() {
    $httpBackend.expectGET('http://localhost:3000/api/facebook/spend_accounts.json');
    $httpBackend.whenGET('http://localhost:3000/api/facebook/spend_accounts.json').respond([
      {email: 'me@unifiedsocial.com'}
    ]);
  });

  it('fetches the users Spend Accounts', function() {
    var result;

    AssetManager.getSpendAccounts('facebook').then(function(data) {
      result = data;
    });

    $httpBackend.flush();

    expect(result.data[0].email).toBe('me@unifiedsocial.com');
  });

});

describe('#getAdAccounts', function() {

  beforeEach(function() {
    $httpBackend.expectGET('http://localhost:3000/api/facebook/ad_accounts/1.json').respond([
      {
        "id": 1,
        "spend_account_id": 1,
        "name": "Unified",
        "initiatives": 3,
        "audiences": 5,
        "pixels": 5,
        "spend": 25000
      }
    ]);
  });

  it('fetches the Spend Accounts Ad Accounts', function() {
    var result;

    AssetManager.getAdAccounts('facebook', '1').then(function(data) {
      result = data;
    });

    $httpBackend.flush();

    expect(result.data[0].name).toBe('Unified');
  });

});

describe('#getAudiencesSummaryData', function() {

  beforeEach(function() {
    $httpBackend.expectGET('http://localhost:3000/api/facebook/audiences_summary_data/1.json').respond([
      {
        'id': 'facebook_id1',
        'name': 'A Name of audience',
        'source': {
          'type': 'Website',
          'detail': 'Custom Audience'
        },
        'count': 2500,
        'timeCreated': new Date('Fri Aug 08 2014 10:29:43 GMT-0400 (EDT)'),
        'status': {
          'deliveryStatus': 'NOT READY',
          'deliveryDescription': 'Audience is < 20 people',
          'operationStatus': 'Operation status??',
          'operationDescription': 'Operation description??'
        }
      },
      {
        'id': 'facebook_id2',
        'name': 'B Name of audience',
        'source': {
          'type': 'Lookalike',
          'detail': 'Custom Audience'
        },
        'count': 2700,
        'timeCreated': new Date('Fri Aug 05 2014 10:29:43 GMT-0400 (EDT)'),
        'status': {
          'deliveryStatus': 'READY',
          'deliveryDescription': 'Audience is < 20 people',
          'operationStatus': 'Operation status??',
          'operationDescription': 'Operation description??'
        }
      }
    ]);
  });

  it('fetches the custom audience summary data', function() {
    var result;

    AssetManager.getAudiencesSummaryData('facebook', '1').then(function(data) {
      result = data;
    });

    $httpBackend.flush();

    expect(result.data[0].name).toBe('A Name of audience');
  });

});
AssetManager.js

(function() {
  'use strict';

   angular
     .module('us.assetManager', ['ui.router'])
     .config(function ($stateProvider, $urlRouterProvider) {
       // catch all route
      $urlRouterProvider.otherwise('/facebook/custom_audiences');

  $stateProvider
    .state('fbCustomAudiences', {
      abstract: true,
      templateUrl: '/common/views/layout.html',
      controller: 'CustomAudiencesCtrl as audiences',
      data: {
        network: 'facebook'
      },
      resolve: {
        getSpendAccounts: function(AssetManager) {
          return AssetManager.getSpendAccounts('facebook');
        }
      }
    })
    .state('fbCustomAudiences.root', {
      url: '/facebook/custom_audiences',
      views: {
        'breadcrumbs': {
          templateUrl: 'facebook/views/breadcrumbs.html'
        },
        'sidebar': {
          templateUrl: 'facebook/views/sidebar.html'
        },
        'acctControls': {
          templateUrl: 'facebook/views/controls.html'
        },
        'table': {
          templateUrl: 'facebook/views/custom-audiences-table.html'
        }
      }
    })
    .state('fbCustomAudiences.spendAccount', {
      url: '/facebook/custom_audiences/:spendAccountId',
      views: {
        'breadcrumbs': {
          templateUrl: 'facebook/views/breadcrumbs.html'
        },
        'sidebar': {
          templateUrl: 'facebook/views/sidebar.html'
        },
        'acctControls': {
          templateUrl: 'facebook/views/controls.html'
        },
        'table': {
          templateUrl: 'facebook/views/custom-audiences-table.html'
        }
      },
      resolve: {
        getAdAccounts: function(getSpendAccounts, AssetManager, $stateParams) {
          var spendAccountId = parseInt($stateParams.spendAccountId);

          // set the selectedSpendAccount for the dropdown
          AssetManager.selectedSpendAccount = _.find(getSpendAccounts.data, function(spendAccount) {
            return spendAccount.id === spendAccountId;
          });

          return AssetManager.getAdAccounts('facebook', spendAccountId);
        }
      }
    })
    .state('fbCustomAudiences.spendAccount.adAccount', {
      url: '/:adAccountId',
      views: {
        'breadcrumbs': {
          templateUrl: 'facebook/views/breadcrumbs.html'
        },
        'sidebar': {
          templateUrl: 'facebook/views/sidebar.html'
        },
        'acctControls': {
          templateUrl: 'facebook/views/controls.html'
        },
        'table': {
          templateUrl: 'facebook/views/custom-audiences-table.html'
        }
      },
      resolve: {
        getCustomAudiences: function(getAdAccounts, AssetManager, $stateParams) {
          var adAccountId = parseInt($stateParams.adAccountId);

          // set the selectedAdAccount for the dropdown
          AssetManager.selectedAdAccount = _.find(getAdAccounts.data, function(adAccount) {
            return adAccount.id === adAccountId;
          });

          return AssetManager.getAudiencesSummaryData('facebook', adAccountId);
        }
      }
    })
  });
})();
(function() {
'use strict';

angular
  .module('us.assetManager')
  .factory('AssetManager', AssetManager);


AssetManager.$inject = ['$http', '$state'];

function AssetManager($http, $state) {

// domain for HTTP endpoints
// StackOverflow doesnt allow localhost so just wrote domain
var domain = 'http://domain:3000/api/';

var spendAccounts = [],
    adAccounts = [],
    audiencesSummaryData = [],
    selectedSpendAccount = {},
    selectedAdAccount = {},
    selectedAudience = {},
    placeholder = null;

var factory = {
  spendAccounts: spendAccounts,
  adAccounts: adAccounts,
  selectedSpendAccount: selectedSpendAccount,
  audiencesSummaryData: audiencesSummaryData,
  selectedAdAccount: selectedAdAccount,
  selectedAudience: selectedAudience,
  placeholder: placeholder,
  getSpendAccounts: getSpendAccounts,
  getAdAccounts: getAdAccounts,
  getAudiencesSummaryData: getAudiencesSummaryData,
  getAudience: getAudience,
  createAudience: createAudience,
  editAudience: editAudience,
  deleteAudience: deleteAudience,
  setSelectedSpendAccount: setSelectedSpendAccount,
  setSelectedAdAccount: setSelectedAdAccount,
  hasSelectedSpendAccount: hasSelectedSpendAccount,
  hasSelectedAdAccount: hasSelectedAdAccount,
  hasSelectedAccounts: hasSelectedAccounts,
  setPlaceholder: setPlaceHolder
};

return factory;

// all URLs will change domains

function getSpendAccounts(socialNetwork) {
  var url = domain + socialNetwork + '/spend_accounts.json',
      AssetManager = this;

  return $http.get(url)
    .success(function(data) {
      AssetManager.spendAccounts = data;
    })
    .error(function() {
      console.log('Could not retrieve Spend Accounts.');
    });
}

function getAdAccounts(socialNetwork, spendAccountId) {
  var url = domain + socialNetwork + '/ad_accounts/' + spendAccountId + '.json'
      AssetManager = this;

  return $http.get(url)
    .success(function(data) {
      AssetManager.adAccounts = data;
    })
    .error(function() {
      console.log('Could not retrieve Ad Accounts.');
    });
}

function getAudiencesSummaryData(socialNetwork, adAccountId) {
  var url = domain + socialNetwork + '/audiences_summary_data/' + adAccountId + '.json',
      AssetManager = this;

  return $http.get(url)
    .success(function(data) {
      AssetManager.audiencesSummaryData = data;
    })
    .error(function() {
      console.log('Could not retrieve Audiences summary data.');
    });
}

function getAudience(socialNetwork, adAccountId, audienceId) {
  var url = domain + socialNetwork + '/audience/' + adAccountId + '/' + audienceId + '.json',
      AssetManager = this;

  return $http.get(url)
    .success(function(data) {
      AssetManager.selectedAudience = data;
    })
    .error(function() {
      console.log('Could not retrieve Audience with id: ' + audienceId);
    });
}
(function() {
'use strict';

describe('AssetManager', function() {

var AssetManager, $httpBackend;

// If the app isn't broken into smaller modules,
// we must load the entire app for each test
beforeEach(function() {
  module('us.assetManager');

  inject(function(_$httpBackend_, _AssetManager_) {
    $httpBackend = _$httpBackend_;
    AssetManager = _AssetManager_
  });

});

afterEach(function() {
  $httpBackend.verifyNoOutstandingExpectation();
  $httpBackend.verifyNoOutstandingRequest();
});

describe('#getSpendAccounts', function() {

  beforeEach(function() {
    $httpBackend.expectGET('http://localhost:3000/api/facebook/spend_accounts.json');
    $httpBackend.whenGET('http://localhost:3000/api/facebook/spend_accounts.json').respond([
      {email: 'me@unifiedsocial.com'}
    ]);
  });

  it('fetches the users Spend Accounts', function() {
    var result;

    AssetManager.getSpendAccounts('facebook').then(function(data) {
      result = data;
    });

    $httpBackend.flush();

    expect(result.data[0].email).toBe('me@unifiedsocial.com');
  });

});

describe('#getAdAccounts', function() {

  beforeEach(function() {
    $httpBackend.expectGET('http://localhost:3000/api/facebook/ad_accounts/1.json').respond([
      {
        "id": 1,
        "spend_account_id": 1,
        "name": "Unified",
        "initiatives": 3,
        "audiences": 5,
        "pixels": 5,
        "spend": 25000
      }
    ]);
  });

  it('fetches the Spend Accounts Ad Accounts', function() {
    var result;

    AssetManager.getAdAccounts('facebook', '1').then(function(data) {
      result = data;
    });

    $httpBackend.flush();

    expect(result.data[0].name).toBe('Unified');
  });

});

describe('#getAudiencesSummaryData', function() {

  beforeEach(function() {
    $httpBackend.expectGET('http://localhost:3000/api/facebook/audiences_summary_data/1.json').respond([
      {
        'id': 'facebook_id1',
        'name': 'A Name of audience',
        'source': {
          'type': 'Website',
          'detail': 'Custom Audience'
        },
        'count': 2500,
        'timeCreated': new Date('Fri Aug 08 2014 10:29:43 GMT-0400 (EDT)'),
        'status': {
          'deliveryStatus': 'NOT READY',
          'deliveryDescription': 'Audience is < 20 people',
          'operationStatus': 'Operation status??',
          'operationDescription': 'Operation description??'
        }
      },
      {
        'id': 'facebook_id2',
        'name': 'B Name of audience',
        'source': {
          'type': 'Lookalike',
          'detail': 'Custom Audience'
        },
        'count': 2700,
        'timeCreated': new Date('Fri Aug 05 2014 10:29:43 GMT-0400 (EDT)'),
        'status': {
          'deliveryStatus': 'READY',
          'deliveryDescription': 'Audience is < 20 people',
          'operationStatus': 'Operation status??',
          'operationDescription': 'Operation description??'
        }
      }
    ]);
  });

  it('fetches the custom audience summary data', function() {
    var result;

    AssetManager.getAudiencesSummaryData('facebook', '1').then(function(data) {
      result = data;
    });

    $httpBackend.flush();

    expect(result.data[0].name).toBe('A Name of audience');
  });

});
AssetManager.spec.js

(function() {
  'use strict';

   angular
     .module('us.assetManager', ['ui.router'])
     .config(function ($stateProvider, $urlRouterProvider) {
       // catch all route
      $urlRouterProvider.otherwise('/facebook/custom_audiences');

  $stateProvider
    .state('fbCustomAudiences', {
      abstract: true,
      templateUrl: '/common/views/layout.html',
      controller: 'CustomAudiencesCtrl as audiences',
      data: {
        network: 'facebook'
      },
      resolve: {
        getSpendAccounts: function(AssetManager) {
          return AssetManager.getSpendAccounts('facebook');
        }
      }
    })
    .state('fbCustomAudiences.root', {
      url: '/facebook/custom_audiences',
      views: {
        'breadcrumbs': {
          templateUrl: 'facebook/views/breadcrumbs.html'
        },
        'sidebar': {
          templateUrl: 'facebook/views/sidebar.html'
        },
        'acctControls': {
          templateUrl: 'facebook/views/controls.html'
        },
        'table': {
          templateUrl: 'facebook/views/custom-audiences-table.html'
        }
      }
    })
    .state('fbCustomAudiences.spendAccount', {
      url: '/facebook/custom_audiences/:spendAccountId',
      views: {
        'breadcrumbs': {
          templateUrl: 'facebook/views/breadcrumbs.html'
        },
        'sidebar': {
          templateUrl: 'facebook/views/sidebar.html'
        },
        'acctControls': {
          templateUrl: 'facebook/views/controls.html'
        },
        'table': {
          templateUrl: 'facebook/views/custom-audiences-table.html'
        }
      },
      resolve: {
        getAdAccounts: function(getSpendAccounts, AssetManager, $stateParams) {
          var spendAccountId = parseInt($stateParams.spendAccountId);

          // set the selectedSpendAccount for the dropdown
          AssetManager.selectedSpendAccount = _.find(getSpendAccounts.data, function(spendAccount) {
            return spendAccount.id === spendAccountId;
          });

          return AssetManager.getAdAccounts('facebook', spendAccountId);
        }
      }
    })
    .state('fbCustomAudiences.spendAccount.adAccount', {
      url: '/:adAccountId',
      views: {
        'breadcrumbs': {
          templateUrl: 'facebook/views/breadcrumbs.html'
        },
        'sidebar': {
          templateUrl: 'facebook/views/sidebar.html'
        },
        'acctControls': {
          templateUrl: 'facebook/views/controls.html'
        },
        'table': {
          templateUrl: 'facebook/views/custom-audiences-table.html'
        }
      },
      resolve: {
        getCustomAudiences: function(getAdAccounts, AssetManager, $stateParams) {
          var adAccountId = parseInt($stateParams.adAccountId);

          // set the selectedAdAccount for the dropdown
          AssetManager.selectedAdAccount = _.find(getAdAccounts.data, function(adAccount) {
            return adAccount.id === adAccountId;
          });

          return AssetManager.getAudiencesSummaryData('facebook', adAccountId);
        }
      }
    })
  });
})();
(function() {
'use strict';

angular
  .module('us.assetManager')
  .factory('AssetManager', AssetManager);


AssetManager.$inject = ['$http', '$state'];

function AssetManager($http, $state) {

// domain for HTTP endpoints
// StackOverflow doesnt allow localhost so just wrote domain
var domain = 'http://domain:3000/api/';

var spendAccounts = [],
    adAccounts = [],
    audiencesSummaryData = [],
    selectedSpendAccount = {},
    selectedAdAccount = {},
    selectedAudience = {},
    placeholder = null;

var factory = {
  spendAccounts: spendAccounts,
  adAccounts: adAccounts,
  selectedSpendAccount: selectedSpendAccount,
  audiencesSummaryData: audiencesSummaryData,
  selectedAdAccount: selectedAdAccount,
  selectedAudience: selectedAudience,
  placeholder: placeholder,
  getSpendAccounts: getSpendAccounts,
  getAdAccounts: getAdAccounts,
  getAudiencesSummaryData: getAudiencesSummaryData,
  getAudience: getAudience,
  createAudience: createAudience,
  editAudience: editAudience,
  deleteAudience: deleteAudience,
  setSelectedSpendAccount: setSelectedSpendAccount,
  setSelectedAdAccount: setSelectedAdAccount,
  hasSelectedSpendAccount: hasSelectedSpendAccount,
  hasSelectedAdAccount: hasSelectedAdAccount,
  hasSelectedAccounts: hasSelectedAccounts,
  setPlaceholder: setPlaceHolder
};

return factory;

// all URLs will change domains

function getSpendAccounts(socialNetwork) {
  var url = domain + socialNetwork + '/spend_accounts.json',
      AssetManager = this;

  return $http.get(url)
    .success(function(data) {
      AssetManager.spendAccounts = data;
    })
    .error(function() {
      console.log('Could not retrieve Spend Accounts.');
    });
}

function getAdAccounts(socialNetwork, spendAccountId) {
  var url = domain + socialNetwork + '/ad_accounts/' + spendAccountId + '.json'
      AssetManager = this;

  return $http.get(url)
    .success(function(data) {
      AssetManager.adAccounts = data;
    })
    .error(function() {
      console.log('Could not retrieve Ad Accounts.');
    });
}

function getAudiencesSummaryData(socialNetwork, adAccountId) {
  var url = domain + socialNetwork + '/audiences_summary_data/' + adAccountId + '.json',
      AssetManager = this;

  return $http.get(url)
    .success(function(data) {
      AssetManager.audiencesSummaryData = data;
    })
    .error(function() {
      console.log('Could not retrieve Audiences summary data.');
    });
}

function getAudience(socialNetwork, adAccountId, audienceId) {
  var url = domain + socialNetwork + '/audience/' + adAccountId + '/' + audienceId + '.json',
      AssetManager = this;

  return $http.get(url)
    .success(function(data) {
      AssetManager.selectedAudience = data;
    })
    .error(function() {
      console.log('Could not retrieve Audience with id: ' + audienceId);
    });
}
(function() {
'use strict';

describe('AssetManager', function() {

var AssetManager, $httpBackend;

// If the app isn't broken into smaller modules,
// we must load the entire app for each test
beforeEach(function() {
  module('us.assetManager');

  inject(function(_$httpBackend_, _AssetManager_) {
    $httpBackend = _$httpBackend_;
    AssetManager = _AssetManager_
  });

});

afterEach(function() {
  $httpBackend.verifyNoOutstandingExpectation();
  $httpBackend.verifyNoOutstandingRequest();
});

describe('#getSpendAccounts', function() {

  beforeEach(function() {
    $httpBackend.expectGET('http://localhost:3000/api/facebook/spend_accounts.json');
    $httpBackend.whenGET('http://localhost:3000/api/facebook/spend_accounts.json').respond([
      {email: 'me@unifiedsocial.com'}
    ]);
  });

  it('fetches the users Spend Accounts', function() {
    var result;

    AssetManager.getSpendAccounts('facebook').then(function(data) {
      result = data;
    });

    $httpBackend.flush();

    expect(result.data[0].email).toBe('me@unifiedsocial.com');
  });

});

describe('#getAdAccounts', function() {

  beforeEach(function() {
    $httpBackend.expectGET('http://localhost:3000/api/facebook/ad_accounts/1.json').respond([
      {
        "id": 1,
        "spend_account_id": 1,
        "name": "Unified",
        "initiatives": 3,
        "audiences": 5,
        "pixels": 5,
        "spend": 25000
      }
    ]);
  });

  it('fetches the Spend Accounts Ad Accounts', function() {
    var result;

    AssetManager.getAdAccounts('facebook', '1').then(function(data) {
      result = data;
    });

    $httpBackend.flush();

    expect(result.data[0].name).toBe('Unified');
  });

});

describe('#getAudiencesSummaryData', function() {

  beforeEach(function() {
    $httpBackend.expectGET('http://localhost:3000/api/facebook/audiences_summary_data/1.json').respond([
      {
        'id': 'facebook_id1',
        'name': 'A Name of audience',
        'source': {
          'type': 'Website',
          'detail': 'Custom Audience'
        },
        'count': 2500,
        'timeCreated': new Date('Fri Aug 08 2014 10:29:43 GMT-0400 (EDT)'),
        'status': {
          'deliveryStatus': 'NOT READY',
          'deliveryDescription': 'Audience is < 20 people',
          'operationStatus': 'Operation status??',
          'operationDescription': 'Operation description??'
        }
      },
      {
        'id': 'facebook_id2',
        'name': 'B Name of audience',
        'source': {
          'type': 'Lookalike',
          'detail': 'Custom Audience'
        },
        'count': 2700,
        'timeCreated': new Date('Fri Aug 05 2014 10:29:43 GMT-0400 (EDT)'),
        'status': {
          'deliveryStatus': 'READY',
          'deliveryDescription': 'Audience is < 20 people',
          'operationStatus': 'Operation status??',
          'operationDescription': 'Operation description??'
        }
      }
    ]);
  });

  it('fetches the custom audience summary data', function() {
    var result;

    AssetManager.getAudiencesSummaryData('facebook', '1').then(function(data) {
      result = data;
    });

    $httpBackend.flush();

    expect(result.data[0].name).toBe('A Name of audience');
  });

});

代码和测试中的URL是不同的。在测试中,您模拟了对的请求

'http://localhost:3000/api/facebook/spend_accounts.json'
但是根据你的密码

var domain = 'http://domain:3000/api/';    
...
function getSpendAccounts(socialNetwork) {
      var url = domain + socialNetwork + '/spend_accounts.json',
          AssetManager = this;
    //do request..
    }
url应该是

'http://domain:3000/api/facebook/spend_accounts.json'

看看。顺便说一句,如果你使用mock,为什么要使用真正的服务?@Whisher谢谢!关于为什么会发生这种情况,有什么解释吗?对不起,但这是我发现的唯一有用的关于ui路由器测试问题的链接:(顺便说一句,我想你只需要当它不是针对你的问题,但可能是可以的时候help@Whisher关于如何使用它的一个问题…在我的例子中,ExpectTransitiono是否采用抽象状态(FBCustomViewer)或者$urlRouterProvider重定向到的url处初始化的路由(fbcustompatiences.root)…我还想,什么时候是为了创建e2e测试的模拟API,而expectGET用于测试是否发出了请求?您是否发现使用1比另一个更好?