sam*_*207 23 javascript testing angularjs karma-jasmine ionic-framework
我正在尝试为我的Angular控制器编写一个测试,我正在使用jasmine
karma
它angular-mocks
,但一直在收到错误ReferenceError: Can't find variable: module
.
我有一点搜索,但我已经有了angular-mocks
我的凉亭.
我在这里可以缺少什么?
以下是我的代码:
#controller
angular.module('cook_book_ctrl', [])
.controller('cookBookCtrl', function($scope, CookBook, CookBookRecipesService){
$scope.cookbookoptions = true;
CookBook.list()
.success(function(data){
$scope.recipeList = data;
CookBookRecipesService.loadCookBookRecipes($scope.recipeList);
})
.error(function(error){
})
});
#controller test
describe('CookBook controller spec', function(){
var $httpBackend, $rootScope, createController, authRequestHandler
beforeEach(module('cook_book_ctrl'));
})
#bower.json
{
"name": "HelloIonic",
"private": "true",
"devDependencies": {
"ionic": "driftyco/ionic-bower#1.0.0",
"ionic-service-analytics": "master",
"ionic-service-core": "~0.1.4",
"angular-mocks": "1.3.13"
},
"dependencies": {
"ng-cordova-oauth": "~0.1.2",
"ng-tags-input": "~2.3.0",
"angular": "~1.4.0",
"underscore": "~1.8.3",
"materialize": "~0.97.0"
},
"resolutions": {
"angular": "~1.4.0"
}
}
beforeEach(module('cook_book_ctrl'));
})
Run Code Online (Sandbox Code Playgroud)
更新:为清晰起见添加了屏幕截图
Reb*_*nix 33
除了angular-mocks
通过凉亭安装外,记得angular-mocks.js
在你的karma配置文件中添加引用,如下所示
config.set({
basePath: '../',
port: '8000',
files: [
'bower_components/angular/angular.js',
'bower_components/angular-mocks/angular-mocks.js',
...
]
Run Code Online (Sandbox Code Playgroud)
wit*_*0ld 11
在我的例子中,它也是关于karma.conf.js中文件路径的错误顺序.
是:
// list of files / patterns to load in the browser
files: [
'tests/*.test.js', // this should not be as first!
'bower_components/angular/angular.min.js',
'bower_components/angular-mocks/angular-mocks.js',
'app/*.js',
],
Run Code Online (Sandbox Code Playgroud)
应该:
// list of files / patterns to load in the browser
files: [
'bower_components/angular/angular.min.js',
'bower_components/angular-mocks/angular-mocks.js',
'app/*.js',
'tests/*.test.js' // now it's cool
],
Run Code Online (Sandbox Code Playgroud)
也许是显而易见的事情,也 ;-)
归档时间: |
|
查看次数: |
27977 次 |
最近记录: |