Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to use wild cards in angularjs mocks

Tags:

angularjs

Is it possible to use wild cards in angular mocks? for example:

$httpBackend.when('GET', '/api/checklists/*').respond({ userId: 'userX' }, { 'A-Token': 'xxx' });

rather than:

$httpBackend.when('GET', '/api/checklists/123').respond({ userId: 'userX' }, { 'A-Token': 'xxx' });
like image 613
Al Polden Avatar asked Sep 04 '13 15:09

Al Polden


1 Answers

The documentation suggests that it takes in a regular expression, so you can do something like this:

$httpBackend.when('GET', /\/api\/checklists\/[1-9][0-9]*/)

This will require the match an integer ID with a length of at least 1, not starting with zero. Of course, this is just an example. Create your own regular expressions to match.

like image 154
Brian Genisio Avatar answered Nov 07 '22 20:11

Brian Genisio