mock $httpBackend regex not matched

后端 未结 4 1095
醉梦人生
醉梦人生 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:16

    There are two problems with your code:

    1. Enclosing an expression in '...' makes it a string (even if it looks like a regular expression.

    2. You must include the leading / in your pattern.


    Your code should be modified like this:

    $httpBackend.whenGET(/^\/rest\/find-reservations\?.*/).respond(function () {
        return [200, 'success', {}];
    });
    

提交回复
热议问题