我是测试角度测试的新手,所以我需要专业人员的手
我使用karma,jasmine和phantomjs我只是按照视频tuts
所以我完成了配置并尝试了我的测试
这里是我的业力骗局
// Karma configuration
// Generated on Fri Feb 24 2017 09:59:10 GMT+0800 (PHT)
module.exports = function(config) {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['jasmine'],
// list of files / patterns to load in the browser
files: [
'../../bower_components/angular/angular.js',
'../../bower_components/angular-mocks/angular-mocks.js',
'../app/caes/controllers/positions/PositionIndexCtrl.coffee',
'unit/*.js'
],
// list of files to exclude
exclude: [
],
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
},
// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress'],
// web server port
port: 9876,
// enable / disable colors in the output (reporters and logs)
colors: true,
// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,
// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['PhantomJS'],
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: false,
// Concurrency level
// how many browser should be started simultaneous
concurrency: Infinity
})
}
我的单元测试testingPositionCtrlSpec.js
describe('Testing Position Suite', function () {
describe('Testing Position Controller',function () {
it('Should initialize the position in the scope ', function () {
module('CaesApp');
var scope = {};
var ctrl;
inject(function ($controller) {
ctrl = $controller('PositionIndexCtrl', {$scope:scope})
});
expect($scope.position).toBeDefine();
});
});
});
这是我测试PositionIndexCtrl.coffee的控制器
#= require ./../../module
PositionIndexCtrl = ($scope, $resource, $route, $mdDialog, Position)->
@positions = Position::list.query()
@showNew = (ev)->
position = new Position()
$mdDialog.show
controller: "PositionNewDialogCtrl"
templateUrl: '/templates/positions/new'
parent: angular.element(document.body)
targetEvent: ev
clickOutsideToClose:true
fullscreen: @customFullscreen
locals:
position: position
$scope.edit = (rowId) ->
position = Position.get(id: rowId)
$mdDialog.show
controller: "PositionEditDialogCtrl"
templateUrl: '/templates/positions/edit'
parent: angular.element(document.body)
clickOutsideToClose:true
fullscreen: @customFullscreen
locals:
position: position
$scope.delete = (rowId) ->
Position.get { id: rowId }, (position) ->
confirm = $mdDialog.confirm().title('Would you like to delete '+ position.name + ' Position').targetEvent(rowId).ok('Yes!').cancel('Cancel')
$mdDialog.show(confirm).then (->
position.$remove ->
console.log('Deleted Success!')
$route.reload()
)
return
PositionIndexCtrl.$inject = ["$scope", "$resource", "$route", "$mdDialog", "Position"]
angular
.module "CaesApp"
.controller "PositionIndexCtrl", PositionIndexCtrl
终端中的错误
PhantomJS 2.1.1(Mac OS X 0.0.0)错误 SyntaxError:无效字符:'#' at /Users/cdasia-tsd/Desktop/revampCAES/app/assets/javascripts/app/caes/controllers/positions/PositionIndexCtrl.coffee:1
我不知道为什么他认为'#'是错误的?
我的假设
如果有人遇到此请分享您的知识
答案 0 :(得分:1)
在业力运行之前,你必须将你的coffescript编译成JavaScript。 Karma无法运行coffescript,没有直接运行coffescript,它总是被编译成JavaScript。
您可以使用https://github.com/karma-runner/karma-coffee-preprocessor