diff options
| author | Misko Hevery | 2010-04-27 11:18:08 -0700 |
|---|---|---|
| committer | Misko Hevery | 2010-04-27 11:18:08 -0700 |
| commit | fce48eb60a47be87a3d95e0750e54c19c2a346d0 (patch) | |
| tree | 6a866e1dd82c43de9cef61e13a98a79442a59a4e /test/angular-mocks.js | |
| parent | b275403465cdc581804bc74bf12e243edd642a42 (diff) | |
| download | angular.js-fce48eb60a47be87a3d95e0750e54c19c2a346d0.tar.bz2 | |
resources now use browser mock
Diffstat (limited to 'test/angular-mocks.js')
| -rw-r--r-- | test/angular-mocks.js | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/test/angular-mocks.js b/test/angular-mocks.js index 3e272313..715b4d75 100644 --- a/test/angular-mocks.js +++ b/test/angular-mocks.js @@ -23,11 +23,19 @@ */ function MockBrowser() { - var self = this, expectations = {}, requests = []; + var self = this, + expectations = {}, + requests = []; self.url = "http://server"; self.watches = []; - self.xhr = function(method, url, callback) { + self.xhr = function(method, url, data, callback) { + if (isFunction(data)) { + callback = data; + data = null; + } + if (data && isObject(data)) data = angular.toJson(data); + if (data && isString(data)) url += "|" + data; var expect = expectations[method] || {}; var response = expect[url]; if (!response) { @@ -39,7 +47,9 @@ function MockBrowser() { }; self.xhr.expectations = expectations; self.xhr.requests = requests; - self.xhr.expect = function(method, url) { + self.xhr.expect = function(method, url, data) { + if (data && isObject(data)) data = angular.toJson(data); + if (data && isString(data)) url += "|" + data; var expect = expectations[method] || (expectations[method] = {}); return { respond: function(response) { @@ -47,6 +57,10 @@ function MockBrowser() { } }; }; + self.xhr.expectGET = angular.bind(self, self.xhr.expect, 'GET'); + self.xhr.expectPOST = angular.bind(self, self.xhr.expect, 'POST'); + self.xhr.expectDELETE = angular.bind(self, self.xhr.expect, 'DELETE'); + self.xhr.expectPUT = angular.bind(self, self.xhr.expect, 'PUT'); self.xhr.flush = function() { while(requests.length) { requests.pop()(); |
