单元测试用$ httpBackend接收二进制响应

时间:2016-04-18 09:28:30

标签: javascript angularjs unit-testing

我有一个处理来自Web API调用的二进制响应的服务:

$http.get('/endpoint', {
    params: urlparams,
    transformResponse: transform,
    responseType: 'arraybuffer'
});

我正在尝试使用$ httpBackend进行测试:

$httpBackend.expectGET('/endpoint').respond(200, data);

但它不起作用,因为数据会自动转换为JSON,而我找不到在responseType调用中指定expectGET的方法。

如何让expectGET$http.get电话提供二进制回复?我尝试将data转换为ArrayBuffer无效。

1 个答案:

答案 0 :(得分:0)

我遇到了类似的问题并使用过:

$httpBackend.expectGET('/endpoint').respond(200, new Blob([data]));
然而,我必须从1.x将PhantomJs更新为2.x才能工作。

相关问题