简体   繁体   English

获取ReferenceError:无法找到变量:angular

[英]getting ReferenceError: Can't find variable: angular

I am new to yeoman and all the tools it uses. 我是自耕农及其使用的所有工具的新手。 I have created a test project in yeoman and trying to run the test spec in jasmine. 我在自耕农中创建了一个测试项目,并尝试在茉莉花中运行测试规范。 I have installed the jasmine plugin using cmd: 我已经使用cmd安装了jasmine插件:

npm install grunt-contrib-jasmine --save-dev npm install grunt-contrib-jasmine --save-dev

Added a jasmine task in Gruntfile.js 在Gruntfile.js中添加了一个jasmine任务

jasmine: {
        src:    '<%= yeoman.app %>/scripts/{,*/}*.js',
        specs: 'test/spec/{,*/}*.js'
    },

when i run the jasmine task grunt jasmine i get following error:- 当我运行茉莉花任务咕噜茉莉我得到以下错误: -

E:\Personal Projects\yeoman-projects\test-app>grunt jasmine
Running "jasmine:src" (jasmine) task

Testing jasmine specs via phantom
ReferenceError: Can't find variable: angular at
..\..\..\E:\Personal%20Projects\yeoman-projects\test-app\app\scripts\app.js:3

ReferenceError: Can't find variable: angular at
..\..\..\E:\Personal%20Projects\yeoman-projects\test-app\app\scripts\controll
ers\main.js:3

Following is my main.js 以下是我的main.js

'use strict';

angular.module('testAppApp')
  .controller('MainCtrl', function ($scope) {
    $scope.awesomeThings = [
      'HTML5 Boilerplate',
      'AngularJS',
      'Karma'
    ];
  });

and app.js 和app.js.

'use strict';

angular.module('testAppApp', [
  'ngRoute'
])
  .config(function ($routeProvider) {
    $routeProvider
      .when('/', {
        templateUrl: 'views/main.html',
        controller: 'MainCtrl'
      })
      .otherwise({
        redirectTo: '/'
      });
  });

Am i missing something ? 我错过了什么吗?

Thanks, Parikshit 谢谢,Parikshit

under jasmine src you have to include angular.js. 在jasmine src下你必须包含angular.js。 For now you have only included you own scripts. 现在你只包括你自己的脚本。 If you are using yeaoman, they are usally in a folder called bower_components/angular. 如果您使用的是yeaoman,它们通常位于名为bower_components / angular的文件夹中。

To keep your test files clean you should use options.vendor for that. 为了保持测试文件的清洁,您应该使用options.vendor

jasmine: {
    src:    '<%= yeoman.app %>/scripts/{,*/}*.js',
    specs: 'test/spec/{,*/}*.js',
    vendor: 'path/to/angular.js'
},

See the documentation . 请参阅文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM