2017-02-24 107 views
0

我在測試角度測試新的,所以我需要用手一個專業的在那裏PhantomJS 2.1.1(Mac OS X的0.0.0)錯誤語法錯誤:無效字符:「#」

我使用的業力,茉莉和phantomjs我只是跟着視頻TUTS

,所以我完成了config和我盡我的測試

這裏我人緣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 
}) 
} 

我的單元測試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) ERROR SyntaxError: Invalid character: '#' at /Users/cdasia-tsd/Desktop/revampCAES/app/assets/javascripts/app/caes/controllers/positions/PositionIndexCtrl.coffee:1

我不知道爲什麼他認爲 '#' 一個錯誤?

我的假設

  • 他不能讀的CoffeeScript?
  • 我需要聲明#require到我的單元測試嗎?

,如果有人遇到這種請分享你的知識

回答

1

你必須編譯coffescript成JavaScript因緣可以運行它之前。 Karma不能運行coffescript,沒有直接運行coffescript,它總是編譯成JavaScript。

您可以使用https://github.com/karma-runner/karma-coffee-preprocessor

+0

我會嘗試在測試和配置這種解決方案我很新,所以它真的會很難,我 – wiwit

+0

仍然是相同的兄弟 – wiwit

+0

這個評論並沒有告訴我們你嘗試過什麼東西,錯誤是什麼,我們怎麼可能幫忙? –