diff options
| author | DiPeng | 2011-06-24 12:26:44 -0700 | 
|---|---|---|
| committer | Igor Minar | 2011-07-18 00:04:14 -0700 | 
| commit | 7974e7eb5f3821b77691819683f9aa37f3c37473 (patch) | |
| tree | 72eea1f97eb3d7f7d79774a8ed831fdc60dc448b /test/BrowserSpecs.js | |
| parent | f9b4c9da648f81aef1fbee41d24822e420eb56f9 (diff) | |
| download | angular.js-7974e7eb5f3821b77691819683f9aa37f3c37473.tar.bz2 | |
refactor($browser): hide startPoll and poll methods
Breaks $browser.poll() method is moved inline to $browser.startpoll()
Breaks $browser.startpoll() method is made private
Refactor tests to reflect updated browser API
Closes #387
Diffstat (limited to 'test/BrowserSpecs.js')
| -rw-r--r-- | test/BrowserSpecs.js | 55 | 
1 files changed, 19 insertions, 36 deletions
diff --git a/test/BrowserSpecs.js b/test/BrowserSpecs.js index d6eb5697..bf9cfd03 100644 --- a/test/BrowserSpecs.js +++ b/test/BrowserSpecs.js @@ -8,7 +8,9 @@ describe('browser', function(){    }    fakeSetTimeout.flush = function() { -    forEach(setTimeoutQueue, function(fn) { +    var currentTimeoutQueue = setTimeoutQueue; +    setTimeoutQueue = []; +    forEach(currentTimeoutQueue, function(fn) {        fn();      });    }; @@ -364,31 +366,27 @@ describe('browser', function(){    });    describe('poller', function(){ -    beforeEach(function() { -      spyOn(browser, 'startPoller'); -    }); -    it('should call all fns on poll', function(){ +    it('should call functions in pollFns in regular intervals', function(){        var log = '';        browser.addPollFn(function(){log+='a';});        browser.addPollFn(function(){log+='b';});        expect(log).toEqual(''); -      browser.poll(); +      fakeSetTimeout.flush();        expect(log).toEqual('ab'); -      browser.poll(); +      fakeSetTimeout.flush();        expect(log).toEqual('abab');      });      it('should startPoller', function(){ -      var log = ''; -      var setTimeoutSpy = jasmine.createSpy('setTimeout'); -      browser.addPollFn(function(){log+='.';}); -      browser.startPoller.andCallThrough(); -      browser.startPoller(50, setTimeoutSpy); -      expect(log).toEqual('.'); -      expect(setTimeoutSpy.mostRecentCall.args[1]).toEqual(50); -      setTimeoutSpy.mostRecentCall.args[0](); -      expect(log).toEqual('..'); +      expect(setTimeoutQueue.length).toEqual(0); + +      browser.addPollFn(function(){}); +      expect(setTimeoutQueue.length).toEqual(1); + +      //should remain 1 as it is the check fn +      browser.addPollFn(function(){}); +      expect(setTimeoutQueue.length).toEqual(1);      });      it('should return fn that was passed into addPollFn', function() { @@ -396,22 +394,6 @@ describe('browser', function(){        var returnedFn = browser.addPollFn(fn);        expect(returnedFn).toBe(fn);      }); - -    it('should auto start poller when first fn registered', function() { -      browser.addPollFn(function() {}); - -      expect(browser.startPoller).toHaveBeenCalled(); -      expect(browser.startPoller.callCount).toBe(1); -    }); - -    it('should auto start poller only when first fn registered', function() { -      browser.startPoller.andCallThrough(); -      browser.addPollFn(function() {}); -      browser.addPollFn(function() {}); -      browser.addPollFn(function() {}); - -      expect(browser.startPoller.callCount).toBe(1); -    });    }); @@ -421,7 +403,8 @@ describe('browser', function(){        fakeWindow = {          location: {href:"http://server"}, -        document: {} +        document: {}, +        setTimeout: fakeSetTimeout        };        browser = new Browser(fakeWindow, {}, {}); @@ -435,12 +418,12 @@ describe('browser', function(){        fakeWindow.location.href = "http://server/#newHash";        expect(events).toEqual([]); -      browser.poll(); +      fakeSetTimeout.flush();        expect(events).toEqual(['x']);        //don't do anything if url hasn't changed        events = []; -      browser.poll(); +      fakeSetTimeout.flush();        expect(events).toEqual([]);      }); @@ -493,7 +476,7 @@ describe('browser', function(){        browser.onHashChange(callback);        window.location.hash = 'new-hash'; -      browser.startPoller(100, setTimeout); +      browser.addPollFn(function() {});        waitsFor(function() {          return callback.callCount;  | 
