aboutsummaryrefslogtreecommitdiffstats
path: root/test/BrowserSpecs.js
diff options
context:
space:
mode:
authorVojta Jina2011-06-01 17:38:25 +0200
committerIgor Minar2011-06-02 10:50:43 -0700
commitdad26037521ff681f9a3c3d4a9bebf14fb8e38cc (patch)
tree15b5a83a6fd7731a5c50259198591878915c86fd /test/BrowserSpecs.js
parent50076b571da522cf6d2cb92c28519694727e9c31 (diff)
downloadangular.js-dad26037521ff681f9a3c3d4a9bebf14fb8e38cc.tar.bz2
Refactor $browser's lazy start polling
+ unit tests
Diffstat (limited to 'test/BrowserSpecs.js')
-rw-r--r--test/BrowserSpecs.js23
1 files changed, 23 insertions, 0 deletions
diff --git a/test/BrowserSpecs.js b/test/BrowserSpecs.js
index e01506dc..08756904 100644
--- a/test/BrowserSpecs.js
+++ b/test/BrowserSpecs.js
@@ -4,6 +4,7 @@ describe('browser', function(){
function fakeSetTimeout(fn) {
setTimeoutQueue.push(fn);
+ return Math.random();
}
fakeSetTimeout.flush = function() {
@@ -384,6 +385,10 @@ describe('browser', function(){
});
describe('poller', function(){
+ beforeEach(function() {
+ spyOn(browser, 'startPoller');
+ });
+
it('should call all fns on poll', function(){
var log = '';
browser.addPollFn(function(){log+='a';});
@@ -399,6 +404,7 @@ describe('browser', 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);
@@ -411,6 +417,22 @@ 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);
+ });
});
@@ -424,6 +446,7 @@ describe('browser', function(){
};
browser = new Browser(fakeWindow, {}, {});
+ browser.startPoller = function() {};
var events = [];