![](/img/trans.png)
[英]jasmine tests in karma: Uncaught ReferenceError: require 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
足夠奇怪的包含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: []
刪除files: []
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.