我的文件夹结构如下:
src
-cars
car.controller.js
car.controller.spec.js
car.test-data.json
在我的spec文件中我正在读取json文件,如下所示:
var sampleData = readJSON('./car.test-data.json')
但是我一直收到错误..找不到文件。
我尝试了许多不同的路径..似乎没有工作
答案 0 :(得分:0)
我终于找到了我在博客上找到的替代解决方案:
mockedDashboardJSON.js:
'use strict'
angular.module('mockedDashboardJSON',[])
.value('defaultJSON',{
fakeData1:{'really':'fake2'},
fakeData2:{'history':'faked'}
});
Then in your test file:
beforeEach(module('yourApp','mockedDashboardJSON'));
var YourControlNameCtrl, scope, $httpBackend, mockedDashboardJSON;
beforeEach(function(_$httpBackend_,defaultJSON){
$httpBackend.when('GET','yourAPI/call/here').respond(defaultJSON.fakeData1);
//Your controller setup
....
});
it('should test my fake stuff',function(){
$httpBackend.flush();
//your test expectation stuff here
....
}