用Jasmine / NodetestingAngular:未捕获types错误“不能设置'mock'的属性undefined

我正在尝试创build“Angular.js in Action”中描述的Jasmineunit testing。 该应用程序运行正常,但我试图运行我的testing时,不断收到此错误在node.js命令提示符。

我的configuration:

module.exports = function(config) { config.set({ // base path, that will be used to resolve files and exclude basePath: '', // frameworks to use frameworks: ['jasmine'], // list of files / patterns to load in the browser files: [ 'javascripts/angular.min.js', 'javascripts/angular-mocks.js', 'javascripts/app.js', 'tests/angelloModelSpec.js', ], 

我的index.html标题:

 <head> <script src="javascripts/angular.min.js" type="text/javascript"></script> <script src="javascripts/angular-mocks.js"></script> <script src="javascripts/app.js"></script> <meta charset="utf-8"> <title>Angello</title> <meta name="description" content="Angello Story Application"> <link rel="stylesheet" href="app.css"> </head> 

我的testing:

 describe('Service: angelloModel', function(){ // load the service's module beforeEach(module('Angello')); var modelService; // Initialize the service beforeEach(inject(function (angelloModel){ modelService = angelloModel; })); describe('#getStatuses', function(){ it('should return seven different statuses', function () { expect(modelService.getStatuses().length).toBe(7); }); }); }); 

在命令提示符下输出:

 Your environment has been set up for using Node.js 0.10.26 (x64) and npm. Your environment has been set up for using Node.js 0.10.26 (x64) and npm. C:\Users\jmclaughlin>karma start karma.conf.js INFO [karma]: Karma v0.10.9 server started at http://localhost:****/ INFO [launcher]: Starting browser Chrome INFO [Chrome 33.0.1750 (Windows 7)]: Connected on socket *************** Chrome 33.0.1750 (Windows 7) ERROR Uncaught TypeError: Cannot set property 'mock' of undefined at C:/Angello/javascripts/angular-mocks.js:17 Chrome 33.0.1750 (Windows 7): Executed 0 of 0 ERROR (0.465 secs / 0 secs) 

当使用每个文件的版本1.0.7时:

 Your environment has been set up for using Node.js 0.10.26 (x64) and npm. C:\Users\myUsername>karma start karma.conf.js INFO [karma]: Karma v0.10.9 server started at http://localhost:****/ INFO [launcher]: Starting browser Chrome INFO [Chrome 33.0.1750 (Windows 7)]: Connected on socket *************** Chrome 33.0.1750 (Windows 7) ERROR Uncaught ReferenceError: angular is not defined at C:/Angello/javascripts/angular-mocks.js:16 Chrome 33.0.1750 (Windows 7): Executed 0 of 0 ERROR (0.064 secs / 0 secs) 

通常这是由于冲突的angular度版本,karma.conf.js中脚本定义的错误顺序,不完整的导入或语法错误造成的。

因为我可以看到你正在testing一个服务,所以把这个服务的js文件包含在这个文件下面(除非它被embedded在app.js中)并且删除错位的逗号(见下面):

 files: [ 'javascripts/angular.min.js', 'javascripts/angular-mocks.js', 'javascripts/app.js', '<include your service js here>', 'tests/angelloModelSpec.js', <<-- and remove this trailing comma ], 

我发现了问题! 我正在编辑错误的configuration文件! 我正在编辑应用程序目录中的configuration文件,但真正的configuration文件是在C:\ Users \ myUsername \ karma.conf.js

感谢您的帮助!