aboutsummaryrefslogtreecommitdiffstats
path: root/test/BrowserSpecs.js
diff options
context:
space:
mode:
authorIgor Minar2010-12-04 23:49:26 -0800
committerIgor Minar2010-12-06 16:45:59 -0800
commit011fa39c2a0b5da843395b538fc4e52e5ade8287 (patch)
treeb5cc7ee72fb2fbcc76da2588822a21c2cedb614c /test/BrowserSpecs.js
parent58d0e8945d772eddbfecbe6a645b2f1c4dd38bf2 (diff)
downloadangular.js-011fa39c2a0b5da843395b538fc4e52e5ade8287.tar.bz2
add $browser.defer and $defer service and fix async xhr cache issue
- Closes #152 ($resource().query() sometimes calls callback before returning, and it shouldn't) - add $browser.defer method - add $defer service - integrate $browser.defer with outstandingRequests counter in $browser - fix all old tests that relied on buggy behavior
Diffstat (limited to 'test/BrowserSpecs.js')
-rw-r--r--test/BrowserSpecs.js39
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() {