【问题标题】:Angular js testing with Grunt使用 Grunt 进行 Angular js 测试
【发布时间】:2013-05-14 14:52:53
【问题描述】:

我在 angularjs 项目中运行测试时遇到问题 - 当我运行“grunt test”时,我得到:

ReferenceError: io 未定义

我通过端口 3000 在本地运行服务器,这是一个 node.js socket.io 服务器 并在 index.html 中实现

<script src="http://localhost:3000/socket.io/socket.io.js"></script>

这是我正在测试的功能:

$scope.editProject = function (dat) {
      $http({
        method: 'PUT',
        url: 'http://some.net/api/project/' + $routeParams.Id,
        data: angular.toJson(dat),
        headers: {'Content-Type': 'application/json'}
      })
      .success(function(d) {
        var time = $filter('date')(new Date(), 'dd/MM HH:mm:ss');
        var loc = '/project/' + $routeParams.Id;
        var head = {
          User : $rootScope.UserInfo.Username,
          Message: 'Some message ',
          Name : dat.ProjectName,
          url: loc,
          date: time,
          icon : 'icon-th-list'
        };
        socket.emit('UpdateHeader', head );
        $location.url('/project/' + $routeParams.Id);
      });
    };

【问题讨论】:

  • 您使用的是哪个测试运行器?你在你的测试运行器中加载 socket.io 吗?

标签: angularjs jasmine yeoman gruntjs


【解决方案1】:

在您的项目中安装最后一个Yeoman,它可以解决您的问题。这将自动安装GruntBower。之后,您可以使用 bower 安装 socket.io 客户端。

grunt test                        # test your app
grunt server                      # preview your app
grunt                             # build the application for deployment

使用Bower component 获取更多包。

【讨论】:

    猜你喜欢
    • 2017-06-10
    • 2016-08-14
    • 1970-01-01
    • 1970-01-01
    • 2015-12-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多