我正在学习使用Karma - Jasmine编写单元测试,以便在AngularJs上构建我的应用程序。我想从json文件加载测试数据。我正在使用Jasmine-Jquery来阅读json灯具。在我的业力配置文件中,我有以下内容:
// 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: [
//dependencies...
'../bower_components/jquery/dist/jquery.js',
'../bower_components/angular/angular.js',
'../bower_components/angular-mocks/angular-mocks.js',
'../bower_components/angular-route/angular-route.js',
// main module app.js.
'../public/app.js',
//all the controllers
'../public/app/controllers/CalculatorCtrl.js',
'../public/app/controllers/ScenaryCtrl.js',
//test dependencies...
'../bower_components/jasmine-jquery/lib/jasmine-jquery.js',
//pattern to include all the test files...
'../public/app/**/*Spec.js',
// JSON fixture
{
pattern: '../public/app/**/*.json',
watched: true,
served: true,
included: false }
],
在我的spec文件中,我这样做:
beforeEach(function(){
jasmine.getJSONFixtures().fixturesPath = 'public/app/controllers/test/fixtures/';
var data=getJSONFixture('myjsonfixtures.json');
console.log(data);
});
当我运行测试用例时,我在控制台中出现以下错误:
18 09 2015 18:02:03.841:INFO [Chrome 45.0.2454 (Windows 8.1 0.0.0)]: Connected on socket 1bzPssO0gtZ_lqHlAAAA with id 52911560
Chrome 45.0.2454 (Windows 8.1 0.0.0): Executed 0 of 2 SUCCESS (0 secs / 0 secs)
18 09 2015 18:02:04.288:WARN [web-server]: 404: /public/app/controllers/test/fixtures/myjsonfixtures.json?_=1442579524156
Chrome 45.0.2454 (Windows 8.1 0.0.0) ERROR
Uncaught Error: JSONFixture could not be loaded: public/app/controllers/test/fixtures/myjsonfixtures.json (status: error, message: undefined)
at G:/My%20Temp%20Angular/Calculator/Karma%20with%20Jasmine/bower_components/jasmine-jquery/lib/jasmine-jquery.js:260
Chrome 45.0.2454 (Windows 8.1 0.0.0): Executed 0 of 2 ERROR (0.089 secs / 0 secs)
我不知道为什么数据没有被加载。我无法理解我所缺少的东西。