diff options
| author | Ken Chen | 2013-08-06 16:53:46 +0100 | 
|---|---|---|
| committer | Pete Bacon Darwin | 2013-08-06 16:54:50 +0100 | 
| commit | 08daa7797bce5207916251d4a0ab3d5c93e5529a (patch) | |
| tree | 243682b2a0ae72f4aa6d378174752f021ca0b695 /test | |
| parent | ac5105b198282139f184eb30a9850e9e212e0acf (diff) | |
| download | angular.js-08daa7797bce5207916251d4a0ab3d5c93e5529a.tar.bz2 | |
feat(ngMock/$httpBackend):  support a matching function for data param
Add support for passing function as validating data:
 - To avoid hacking test method of RegExp
 - Optionally overwrite `toString` method of fn to show validation tips
 - change docs: param description for `when`, `whenPost`, `whenPut`,
   `expect`, `expectPost`, `expectPut`, `expectPATCH`
Closes: #2981
Diffstat (limited to 'test')
| -rw-r--r-- | test/ngMock/angular-mocksSpec.js | 13 | 
1 files changed, 13 insertions, 0 deletions
| diff --git a/test/ngMock/angular-mocksSpec.js b/test/ngMock/angular-mocksSpec.js index 893fe14c..e1873535 100644 --- a/test/ngMock/angular-mocksSpec.js +++ b/test/ngMock/angular-mocksSpec.js @@ -1037,6 +1037,19 @@ describe('ngMock', function() {        }); +      it('should accept data as function', function() { +        var dataValidator = function(data) { +          var json = angular.fromJson(data); +          return !!json.id && json.status === 'N'; +        }; +        var exp = new MockHttpExpectation('POST', '/url', dataValidator); + +        expect(exp.matchData({})).toBe(false); +        expect(exp.match('POST', '/url', '{"id": "xxx", "status": "N"}')).toBe(true); +        expect(exp.match('POST', '/url', {"id": "xxx", "status": "N"})).toBe(true); +      }); + +        it('should ignore data only if undefined (not null or false)', function() {          var exp = new MockHttpExpectation('POST', '/url', null);          expect(exp.matchData(null)).toBe(true); | 
