aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorCaio Cunha2013-10-22 09:41:51 -0400
committerIgor Minar2014-03-18 15:19:26 -0700
commitd6cfcacee101f2738e0a224a3377232ff85f78a4 (patch)
tree4f3237302917e7e12fab43980f528c5007413234 /test
parent299b220f5e05e1d4e26bfd58d0b2fd7329ca76b1 (diff)
downloadangular.js-d6cfcacee101f2738e0a224a3377232ff85f78a4.tar.bz2
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
Diffstat (limited to 'test')
-rw-r--r--test/ngMock/angular-mocksSpec.js11
1 files changed, 11 insertions, 0 deletions
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', /\{.*?\}/);