mock $httpBackend regex not matched

后端 未结 4 1092
醉梦人生
醉梦人生 2021-01-04 06:59

I\'m trying to match an url with a regex. But the follwing regex doesn\'t match.

$httpBackend.whenGET(\'/^rest\\/find-reservations\\?.*/)\').respond(function         


        
4条回答
  •  感情败类
    2021-01-04 07:19

     this.httpBackend.whenGET(new RegExp('.*')).respond(function(){ return [200, 'MISS', {}] });
     this.httpBackend.whenPOST('/report/').respond(function(){return [200, 'HIT', {}] ; });
     this.httpBackend.whenPOST(new RegExp('.*')).respond(function(){ return      [200, 'MISS', {}] });
    
    var _received;
    
    var result = this.reportService.save(new this.Report());
    result.then(function(response){
        _received = response.data;
    });          
    this.httpBackend.flush();
    expect(_received).toBe('HIT');          
    

提交回复
热议问题