내 angularJS 프로젝트에서 내 서비스 테스트를 작성하는 데 몇 가지 어려움이 있습니다. 유닛 테스트에 카르마와 재스민을 사용하고 있습니다. 시작하려면 종속성이없는 서비스를 선택했지만 테스트를 통과하지 못했습니다.서비스/공장 테스트 - AngularJS - 재스민
여기 (커피 스크립트 작성) 내 서비스
angular.module('app').factory 'rankFactory', [ ->
rankFactory = {}
ranks = [
{
id: 0
label: 'RANK0'
}
{
id: 1
label: 'RANK1'
}
]
rankFactory.getRanks = ->
ranks
rankFactory.getRanks = (id) ->
ranks[id]
rankFactory
]
서비스가 잘 작동합니다. 따라서 테스트에서는 그렇지 않습니다. 여기에 내 테스트가 있습니다 :
describe('rank Factory unit tests', function(){
describe ('when I call myService rankFactory.getRanks()', function() {
beforeEach(module('app'));
it('returns ranks', inject(function(rankFactory){
expect(rankFactory.getRanks()).not.to.equal(null);
}))
}
)
});
여러 시간 동안 노력했지만 많은 문제와 문서를 읽었지만 여전히 작동하지 않는 이유를 찾을 수 없습니다. 도와 줄수있으세요?
---------------------------------------------- ------------------편집하다------------------------------- ----------------------------
나는 내 문제가 coffeeScript와 관련이 있다는 것을 알아 냈습니다. 내 컨트롤러, 서비스는 coffeeScript로 작성되었으며 테스트를 시작할 때 내 서비스와 관련된 구문 오류가 발생했습니다. 나는 자바 스크립트 내 테스트를 쓰고 있어요 그리고 나는이 커피 스크립트를 충당하기 위해해야 할 일을 혼란 스러워요
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-ui-router/release/angular-ui-router.js',
'../bower_components/angular-mocks/angular-mocks.js',
'../src/scripts/**/*.coffee',
'../src/scripts/Services/rankService.coffee',
'unit-tests/**/*.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: {
'**/*.coffee': ['coffee']
},
coffeePreprocessor: {
// options passed to the coffee compiler
options: {
bare: true,
sourceMap: false
},
// transforming the filenames
transformPath: function(path) {
return path.replace(/\.coffee$/, '.js')
}
},
// 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_DEBUG,
// 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
})
}
:
여기에 내 구성 파일입니다.
시 : 내가 설치 한 this tutorial에서 다음과 같은 예를 감안할 때 카르마 - 커피 전처리
"무엇이 작동하지 않습니까?", 콘솔의 모든 오류가 있습니까? –
테스트 케이스 설정에 특정 파일을 추가 했습니까? – Rohit
@PankajParkar : coffeeScript 컨트롤러/서비스를 처리 할 수 없습니다. – AsmaG