httpBackend模拟了json文件响应

时间:2015-03-30 08:57:27

标签: javascript angularjs jasmine

我有这个帖子请求将代码模拟到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

谢谢!

1 个答案:

答案 0 :(得分:0)

答案是:

    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')];
    });