httpBackend 模拟了 json 文件响应
httpBackend mocked json file response
我将此 post 请求模拟代码放入 beforeEach 函数
$httpBackend.when('POST', CONFIG.get('MAIN_URL_FOR_REST_SERVICES') + 'actions/search').respond(200,
'[{"name": "all","id": "1"}]'
);
如何将 httpBackend 响应存储到 json 文件中?
[{"name": "all","id": "1"}]
存入actions.json
谢谢!
答案是:
jasmine.getJSONFixtures().fixturesPath = 'base/test/unit/authz/api_mock/';
$httpBackend.when('POST', CONFIG.get('MAIN_URL_FOR_REST_SERVICES') + 'actions/search').respond(function() {
return [200, window.getJSONFixture('actions.json')];
});
我将此 post 请求模拟代码放入 beforeEach 函数
$httpBackend.when('POST', CONFIG.get('MAIN_URL_FOR_REST_SERVICES') + 'actions/search').respond(200,
'[{"name": "all","id": "1"}]'
);
如何将 httpBackend 响应存储到 json 文件中?
[{"name": "all","id": "1"}]
存入actions.json
谢谢!
答案是:
jasmine.getJSONFixtures().fixturesPath = 'base/test/unit/authz/api_mock/';
$httpBackend.when('POST', CONFIG.get('MAIN_URL_FOR_REST_SERVICES') + 'actions/search').respond(function() {
return [200, window.getJSONFixture('actions.json')];
});