我正在学习此视频http://egghead.io/lessons/angularjs-testing-overview
但不是成功或失败,我得到......
INFO [watcher]: Changed file "/Users/kirk/git/kirkstrobeck/learn-angular/egghead/app/main.js".
Chrome 31.0.1650 (Mac OS X 10.9.0) filter reverse should reverse a string FAILED
RangeError: Maximum call stack size exceeded
at reverseFilter (/Users/kirk/git/kirkstrobeck/learn-angular/egghead/test/unit/main.js:7:73)
at reverseFilter (/Users/kirk/git/kirkstrobeck/learn-angular/egghead/test/unit/main.js:8:21)
at reverseFilter (/Users/kirk/git/kirkstrobeck/learn-angular/egghead/test/unit/main.js:8:21)
at reverseFilter (/Users/kirk/git/kirkstrobeck/learn-angular/egghead/test/unit/main.js:8:21)
at reverseFilter (/Users/kirk/git/kirkstrobeck/learn-angular/egghead/test/unit/main.js:8:21)
at reverseFilter (/Users/kirk/git/kirkstrobeck/learn-angular/egghead/test/unit/main.js:8:21)
at reverseFilter (/Users/kirk/git/kirkstrobeck/learn-angular/egghead/test/unit/main.js:8:21)
at reverseFilter (/Users/kirk/git/kirkstrobeck/learn-angular/egghead/test/unit/main.js:8:21)
at reverseFilter (/Users/kirk/git/kirkstrobeck/learn-angular/egghead/test/unit/main.js:8:21)
at reverseFilter (/Users/kirk/git/kirkstrobeck/learn-angular/egghead/test/unit/main.js:8:21)
Error: Declaration Location
at window.inject.angular.mock.inject (/Users/kirk/git/kirkstrobeck/learn-angular/egghead/bower_components/angular-mocks/angular-mocks.js:2086:25)
at null.<anonymous> (/Users/kirk/git/kirkstrobeck/learn-angular/egghead/test/unit/main.js:7:42)
at null.<anonymous> (/Users/kirk/git/kirkstrobeck/learn-angular/egghead/test/unit/main.js:4:10)
at /Users/kirk/git/kirkstrobeck/learn-angular/egghead/test/unit/main.js:2:1
Chrome 31.0.1650 (Mac OS X 10.9.0): Executed 1 of 1 (1 FAILED) ERROR (0.31 secs / 0.02 secs)
我的配置是
// Karma configuration
// Generated on Tue Dec 03 2013 00:57:22 GMT-0800 (PST)
module.exports = function(config) {
config.set({
// base path, that will be used to resolve files and exclude
basePath: '',
// frameworks to use
frameworks: [
'jasmine'
//'requirejs'
],
// list of files / patterns to load in the browser
files: [
'bower_components/angular/angular.js',
'bower_components/angular-resource/angular-resource.js',
'bower_components/angular-mocks/angular-mocks.js',
'app/*.js',
'test/unit/*.js'
],
// list of files to exclude
exclude: [
],
// test results reporter to use
// possible values: 'dots', 'progress', 'junit', 'growl', 'coverage'
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, currently available:
// - Chrome
// - ChromeCanary
// - Firefox
// - Opera
// - Safari (only Mac)
// - PhantomJS
// - IE (only Windows)
browsers: ['Chrome'],
// If browser does not capture in given timeout [ms], kill it
captureTimeout: 60000,
// Continuous Integration mode
// if true, it capture browsers, run tests and exit
singleRun: false
});
};
main.js
// Generated by CoffeeScript 1.6.2
describe('filter', function() {
beforeEach(module('myApp'));
return describe('reverse', function() {
var reverseFilter;
return it('should reverse a string', inject(reverseFilter = function() {
return expect(reverseFilter('ABCD')).toEqual('DCBA');
}));
});
});
好的,现在我的js
没有返回任何内容
// Generated by CoffeeScript 1.6.2
describe('filter', function() {
beforeEach(module('myApp'));
describe('reverse', function() {
var reverseFilter;
it('should reverse a string', inject(reverseFilter = function() {
expect(reverseFilter('ABCD')).toEqual('DCBA');
}));
});
});
我仍然收到此错误
$ karma start
INFO [karma]: Karma v0.10.2 server started at http://localhost:9876/
INFO [launcher]: Starting browser Chrome
INFO [Chrome 31.0.1650 (Mac OS X 10.9.0)]: Connected on socket 7v0AzIkyQdYktlZutK6F
Chrome 31.0.1650 (Mac OS X 10.9.0) filter reverse should reverse a string FAILED
RangeError: Maximum call stack size exceeded
at reverseFilter (/Users/kirk/git/kirkstrobeck/learn-angular/egghead/test/unit/main.js:7:66)
at reverseFilter (/Users/kirk/git/kirkstrobeck/learn-angular/egghead/test/unit/main.js:8:14)
at reverseFilter (/Users/kirk/git/kirkstrobeck/learn-angular/egghead/test/unit/main.js:8:14)
at reverseFilter (/Users/kirk/git/kirkstrobeck/learn-angular/egghead/test/unit/main.js:8:14)
at reverseFilter (/Users/kirk/git/kirkstrobeck/learn-angular/egghead/test/unit/main.js:8:14)
at reverseFilter (/Users/kirk/git/kirkstrobeck/learn-angular/egghead/test/unit/main.js:8:14)
at reverseFilter (/Users/kirk/git/kirkstrobeck/learn-angular/egghead/test/unit/main.js:8:14)
at reverseFilter (/Users/kirk/git/kirkstrobeck/learn-angular/egghead/test/unit/main.js:8:14)
at reverseFilter (/Users/kirk/git/kirkstrobeck/learn-angular/egghead/test/unit/main.js:8:14)
at reverseFilter (/Users/kirk/git/kirkstrobeck/learn-angular/egghead/test/unit/main.js:8:14)
Error: Declaration Location
at window.inject.angular.mock.inject (/Users/kirk/git/kirkstrobeck/learn-angular/egghead/bower_components/angular-mocks/angular-mocks.js:2086:25)
at null.<anonymous> (/Users/kirk/git/kirkstrobeck/learn-angular/egghead/test/unit/main.js:7:35)
at null.<anonymous> (/Users/kirk/git/kirkstrobeck/learn-angular/egghead/test/unit/main.js:4:3)
at /Users/kirk/git/kirkstrobeck/learn-angular/egghead/test/unit/main.js:2:1
Chrome 31.0.1650 (Mac OS X 10.9.0): Executed 1 of 1 (1 FAILED) ERROR (0.132 secs / 0.025 secs)
at /Users/kirk/git/kirkstrobeck/learn-angular/egghead/test/unit/main.js:2:1
Chrome 31.0.1650 (Mac OS X 10.9.0): Executed 1 of 1 (1 FAILED) ERROR (0.288 secs / 0.012 secs)
^Ckirk:egghead kirk$
kirk:egghead kirk$
kirk:egghead kirk$ karma start
INFO [karma]: Karma v0.10.2 server started at http://localhost:9876/
INFO [launcher]: Starting browser Chrome
INFO [Chrome 31.0.1650 (Mac OS X 10.9.0)]: Connected on socket 7v0AzIkyQdYktlZutK6F
Chrome 31.0.1650 (Mac OS X 10.9.0) filter reverse should reverse a string FAILED
RangeError: Maximum call stack size exceeded
at reverseFilter (/Users/kirk/git/kirkstrobeck/learn-angular/egghead/test/unit/main.js:7:66)
at reverseFilter (/Users/kirk/git/kirkstrobeck/learn-angular/egghead/test/unit/main.js:8:14)
at reverseFilter (/Users/kirk/git/kirkstrobeck/learn-angular/egghead/test/unit/main.js:8:14)
at reverseFilter (/Users/kirk/git/kirkstrobeck/learn-angular/egghead/test/unit/main.js:8:14)
at reverseFilter (/Users/kirk/git/kirkstrobeck/learn-angular/egghead/test/unit/main.js:8:14)
at reverseFilter (/Users/kirk/git/kirkstrobeck/learn-angular/egghead/test/unit/main.js:8:14)
at reverseFilter (/Users/kirk/git/kirkstrobeck/learn-angular/egghead/test/unit/main.js:8:14)
at reverseFilter (/Users/kirk/git/kirkstrobeck/learn-angular/egghead/test/unit/main.js:8:14)
at reverseFilter (/Users/kirk/git/kirkstrobeck/learn-angular/egghead/test/unit/main.js:8:14)
at reverseFilter (/Users/kirk/git/kirkstrobeck/learn-angular/egghead/test/unit/main.js:8:14)
Error: Declaration Location
at window.inject.angular.mock.inject (/Users/kirk/git/kirkstrobeck/learn-angular/egghead/bower_components/angular-mocks/angular-mocks.js:2086:25)
at null.<anonymous> (/Users/kirk/git/kirkstrobeck/learn-angular/egghead/test/unit/main.js:7:35)
at null.<anonymous> (/Users/kirk/git/kirkstrobeck/learn-angular/egghead/test/unit/main.js:4:3)
at /Users/kirk/git/kirkstrobeck/learn-angular/egghead/test/unit/main.js:2:1
Chrome 31.0.1650 (Mac OS X 10.9.0): Executed 1 of 1 (1 FAILED) ERROR (0.132 secs / 0.025 secs)
我的coffeescript现在是
describe 'filter', ->
beforeEach module('myApp')
describe 'reverse', ->
it 'should reverse a string', inject (reverseFilter) ->
expect(reverseFilter 'ABCD').toEqual('DCBA')
编译为
// Generated by CoffeeScript 1.6.2
describe('filter', function() {
beforeEach(module('myApp'));
return describe('reverse', function() {
return it('should reverse a string', inject(function(reverseFilter) {
return expect(reverseFilter('ABCD')).toEqual('DCBA');
}));
});
});
答案 0 :(得分:2)
问题是你如何注入reverseFilter
这是你应该怎么做的:
describe('filter', function() {
beforeEach(module('myApp'));
describe('reverse', function() {
it('should reverse a string', inject(function(reverseFilter) {
expect(reverseFilter('ABCD')).toEqual('DCBA');
}));
});
});
考虑在myApp模块中声明了一个名为 reverse 的过滤器:
myApp.filter('reverse', function() {
return function(value) {
//return reversed value here
}
});