Testing Ionic with Jasmine and Karma - Uncaught ReferenceError: angular is not defined

Testing Ionic with Jasmine and Karma - Uncaught ReferenceError: angular is not defined

长话短说,当我 运行 karma.conf.js 我看到 Uncaught ReferenceError: angular is not defined

我开始使用预先存在的 Ionic 项目..并添加一些单元测试。我需要检查我们的 www/index.html ..我没有看到 angular.js 很奇怪..这是原因吗?

这个团队使用 Maven 进行构建,所以我担心我们在构建方面与社区的其他成员不一致。

更新 1:在 www/index.html 的包含的顶部添加 <script type="text/javascript" src="lib/js/angular/angular.js"></script> 无效。

更新 2:index.html 包含离子束 <script src="lib/js/ionic.bundle.js"></script>

Karma.conf.js

// list of files / patterns to load in the browser
files: [
    'www/lib/js/angular/angular.js',
    'www/lib/js/angular/angular-animate.js',
    'www/lib/js/angular/angular-animate.js',
    'www/lib/js/angular/angular-mocks.js',
    'www/lib/js/angular/angular-resource.js',
    'www/lib/js/angular/angular-sanitize.js',
    'www/lib/js/angular-ui/angular-ui-router.js',
    'www/lib/js/ionic.js',
    'www/lib/js/ionic-angular.js',
    'www/js/**/*.js',
    'www/test/jasmine/*.js'
],

Ionic 已经有 Angular,所以你不需要在外部添加 Angular。你应该删除 <script type="text/javascript" src="lib/js/angular/angular.js"></script>

并确保在依赖项中添加 Ionic

angular.module('myApp', ['ionic'])

并且:记得在 index.html

中执行此操作
<body ng-app="myApp"></body>

*可能在 body 标签或 html 标签中,只要确保您添加了它。

编辑

正如@PSL 所说:Ionic Bundle 中有 Angular。所以我想,您应该开始使用 Ionic Bundle 而不再担心它。

如果您不使用 Ionic Bundle,请在您的索引中添加 Angular 的引用,并进行我上面提到的声明。

您的业力文件应该如下所示

// list of files / patterns to load in the browser
    files: [
    //Angular source
    'lib/ionic/js/ionic.bundle.js',
    'lib/angular-mocks/angular-mocks.js',
    'lib/angular-local-storage/dist/angular-local-storage.js',
    'lib/ngCordova/dist/ng-cordova.js',
    'lib/ionic/js/angular-ui/angular-ui-router.js',
    'lib/angular-animate/angular-animate.js',
    'lib/angular-sanitize/angular-sanitize.js',

    //App code
    'js/*.js',
    'js/controllers/*.js',
    'js/services/*.js',

    //Test files
    'test/controllers/*.js'
    ],

如果您没有使用上面的某些文件,只需将其从数组中删除即可 files: []