首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >意外请求: GET模块/home/home.home

意外请求: GET模块/home/home.home
EN

Stack Overflow用户
提问于 2015-09-23 21:59:06
回答 1查看 559关注 0票数 1

我刚刚将应用程序从使用Jade模板引擎改为使用客户端HTML,以提高性能和减少服务器请求。在应用程序中,一切都很好,但是我在更新单元测试时遇到了问题。

我有以下测试:

代码语言:javascript
运行
复制
describe('Registration Controller Tests', function() {
  var $controller, $scope, defer, registerSpy, doesUserExistSpy, auth, RegistrationCtrl;

  beforeEach(module('enigmaApp'));

  beforeEach(inject(function (_$controller_, _$rootScope_, $q) {
    $controller = _$controller_;
    $scope = _$rootScope_;
    defer = $q.defer();

    // Create spies
    registerSpy = jasmine.createSpy('register').and.returnValue(defer.promise);
    doesUserExistSpy = jasmine.createSpy('doesUserExist').and.returnValue(defer.promise);

    auth = {
      register: registerSpy,
      doesUserExist: doesUserExistSpy
    };    

    // Init register controller with mocked services and scope
    RegistrationCtrl = $controller('RegistrationCtrl', {
      $scope: $scope,
      auth: auth
    });

    // digest to update controller with services and scope
    $scope.$digest();
  }));

  describe('RegistrationCtrl.register()', function () {
    beforeEach(function () {
      $scope.user = {
        email: 'bwayne@wayneenterprise.com',
        first_name: 'Bruce',
        last_name: 'Wyane',
        password: 'password123'
      }
    });

    it('should call auth.register() with $scope.user', function () {
      $scope.register();
      expect(auth.register).toHaveBeenCalledWith($scope.user);
    });
});

这将导致以下错误:

代码语言:javascript
运行
复制
Error: Unexpected request: GET modules/home/home.html
No more requests expected

有什么想法吗?我该怎么做才能嘲笑路线?我试过一些东西,但到目前为止都没有用。

附加代码:

RegistrationCtrl

代码语言:javascript
运行
复制
 .controller('RegistrationCtrl', function($scope, $state, auth) {
     $scope.user = {};
     $scope.userExists = false;
     $scope.error = '';

     $scope.register = function() {
       auth.register($scope.user)
       .then(function(response){
         $state.go('secure.user'); 
       })
       .catch(function(err){
         $scope.error = err;
       });
     };
 });
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-09-28 16:44:30

假设您的静态文件都在/modules中:

代码语言:javascript
运行
复制
$httpBackend.whenGET(/modules\/[\w\W]*/).passThrough();
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32750208

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档