diff options
Diffstat (limited to 'test/BrowserSpecs.js')
| -rw-r--r-- | test/BrowserSpecs.js | 39 |
1 files changed, 37 insertions, 2 deletions
diff --git a/test/BrowserSpecs.js b/test/BrowserSpecs.js index 5f28b610..eb43e3c5 100644 --- a/test/BrowserSpecs.js +++ b/test/BrowserSpecs.js @@ -1,8 +1,21 @@ describe('browser', function(){ - var browser, location, head, xhr; + var browser, location, head, xhr, setTimeoutQueue; + + function fakeSetTimeout(fn) { + setTimeoutQueue.push(fn); + } + + fakeSetTimeout.flush = function() { + foreach(setTimeoutQueue, function(fn) { + fn(); + }); + }; + beforeEach(function(){ + setTimeoutQueue = []; + location = {href:"http://server", hash:""}; head = { scripts: [], @@ -14,7 +27,7 @@ describe('browser', function(){ this.open = noop; this.setRequestHeader = noop; this.send = noop; - }); + }, undefined, fakeSetTimeout); }); it('should contain cookie cruncher', function() { @@ -59,6 +72,28 @@ describe('browser', function(){ }); + describe('defer', function() { + it('should execute fn asynchroniously via setTimeout', function() { + var counter = 0; + browser.defer(function() {counter++;}); + expect(counter).toBe(0); + + fakeSetTimeout.flush(); + expect(counter).toBe(1); + }); + + + it('should update outstandingRequests counter', function() { + var callback = jasmine.createSpy('callback'); + browser.defer(callback); + expect(callback).not.wasCalled(); + + fakeSetTimeout.flush(); + expect(callback).wasCalled(); + }); + }); + + describe('cookies', function() { function deleteAllCookies() { |
