From d6cfcacee101f2738e0a224a3377232ff85f78a4 Mon Sep 17 00:00:00 2001 From: Caio Cunha Date: Tue, 22 Oct 2013 09:41:51 -0400 Subject: feat(ngMock.$httpBackend): added support for function as URL matcher It's now possible to pass a function to match the URL in $httpBackend mocked expectations. This gives a more sophisticate control over the URL matching without requiring complex RegExp mantainance or the workaround of creating an object with a `test` function in order to mimic RegExp interface. This approach was suggested in [this thread](https://groups.google.com/d/msg/angular/3QsCUEvvxlM/Q4C4ZIqNIuEJ) Closes #4580 --- test/ngMock/angular-mocksSpec.js | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'test') diff --git a/test/ngMock/angular-mocksSpec.js b/test/ngMock/angular-mocksSpec.js index c2b6108d..b3608013 100644 --- a/test/ngMock/angular-mocksSpec.js +++ b/test/ngMock/angular-mocksSpec.js @@ -1431,6 +1431,17 @@ describe('ngMock', function() { }); + it('should accept url as function', function() { + var urlValidator = function(url) { + return url !== '/not-accepted'; + }; + var exp = new MockHttpExpectation('POST', urlValidator); + + expect(exp.match('POST', '/url')).toBe(true); + expect(exp.match('POST', '/not-accepted')).toBe(false); + }); + + it('should accept data as regexp', function() { var exp = new MockHttpExpectation('POST', '/url', /\{.*?\}/); -- cgit v1.2.3