Javascript 使用$httpBackend接收二进制响应的单元测试
我有一个处理来自web API调用的二进制响应的服务:Javascript 使用$httpBackend接收二进制响应的单元测试,javascript,angularjs,unit-testing,Javascript,Angularjs,Unit Testing,我有一个处理来自web API调用的二进制响应的服务: $http.get('/endpoint', { params: urlparams, transformResponse: transform, responseType: 'arraybuffer' }); 我正在尝试使用$httpBackend对其进行测试: $httpBackend.expectGET('/endpoint').respond(200, data); 但它不起作用,因为数据会自动转换为JS
$http.get('/endpoint', {
params: urlparams,
transformResponse: transform,
responseType: 'arraybuffer'
});
我正在尝试使用$httpBackend对其进行测试:
$httpBackend.expectGET('/endpoint').respond(200, data);
但它不起作用,因为数据会自动转换为JSON,我无法在expectGET
调用中找到指定responseType
的方法
如何使
expectGET
对$http.get
调用提供二进制响应?我尝试将数据
转换为阵列缓冲
,但没有成功。我遇到了类似问题,并使用了:
$httpBackend.expectGET('/endpoint').respond(200, new Blob([data]));
但是,我必须将PhantomJs从1.x更新为2.x,这样才能工作。我遇到了类似的问题,并使用了:
$httpBackend.expectGET('/endpoint').respond(200, new Blob([data]));
不过,我必须将PhantomJs从1.x更新为2.x,才能使其正常工作