是否可以在 Angular 模拟中使用通配符?例如:
$httpBackend.when('GET', '/api/checklists/*').respond({ userId: 'userX' }, { 'A-Token': 'xxx' });
而不是:
$httpBackend.when('GET', '/api/checklists/123').respond({ userId: 'userX' }, { 'A-Token': 'xxx' });
最佳答案
documentation建议它采用正则表达式,因此您可以执行以下操作:
$httpBackend.when('GET', /\/api\/checklists\/[1-9][0-9]*/)
这将需要匹配一个长度至少为 1 的整数 ID,而不是从零开始。当然,这只是一个例子。创建您自己的正则表达式来匹配。
关于angularjs - 是否可以在 angularjs 模拟中使用通配符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18618532/