i'm new in testing a angular test so i need hand for a professional out there
i use karma, jasmine and phantomjs i just follow the video tuts
so i finish the config and i try my test
here my karma congif
// 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
})
}
my unit test 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();
});
});
});
this is the controller i test 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
my error in terminal
PhantomJS 2.1.1 (Mac OS X 0.0.0) ERROR SyntaxError: Invalid character: '#' at /Users/cdasia-tsd/Desktop/revampCAES/app/assets/javascripts/app/caes/controllers/positions/PositionIndexCtrl.coffee:1
i dont know why he consider '#' a error?
my hypothesis
- he cant read coffeescript??
- i need to declare #require to my unit test?
if someone experience this please share your knowledge