我是AngularJS的新手并使用Jasmine进行测试。我有两个用几个httpBackend.whenPOST描述,但我不知道下一个是否可能:
我想要包含两个嵌套的描述,第二个使用来自第一个的所有httpBackend.whenPost。但我希望其中一个httpBackend.whenPost返回另一个具有相同网址的Json。这可能吗?
describe('describe1', function(){
beforeEach(function(){
$httpBackend.whenPOST(/backend\/economicresponsible\/get\/.*/).
respond(function(method, url, data, headers) {
var xmlhttp = new XMLHttpRequest();
xmlhttp.open('POST', 'tests/json/economicData1.json', false);
xmlhttp.send();
return [200, JSON.parse(xmlhttp.response), {}];
});
.... more requests...
});
it('should be test', function(){
get response economicData1.json
});
describe('describe2', function(){
beforeEach(function(){
$httpBackend.whenPOST(/backend\/economicresponsible\/get\/.*/).
respond(function(method, url, data, headers) {
var xmlhttp = new XMLHttpRequest();
xmlhttp.open('POST', 'tests/json/economicData2.json', false);
xmlhttp.send();
return [200, JSON.parse(xmlhttp.response), {}];
});
});
it('should be test 2', function(){
get response economicData2.json
});
});
});