-
Notifications
You must be signed in to change notification settings - Fork 630
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Faster, more consistent tests #740
Changes from 9 commits
5338dbf
3acc6a3
9e1fad6
239a3a8
6df3540
181f720
37a2bc2
f11daab
21d3187
d6e759e
95b12ac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,13 +40,20 @@ describe('$firebaseArray', function () { | |
$utils = $firebaseUtils; | ||
$rootScope = _$rootScope_; | ||
$q = _$q_; | ||
tick = function (cb) { | ||
|
||
firebase.database.enableLogging(function () {tick()}); | ||
tick = function () { | ||
setTimeout(function() { | ||
$q.defer(); | ||
$rootScope.$digest(); | ||
cb && cb(); | ||
}, 1000) | ||
try { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm. We have a flushAll() method that handles try/catch/$timeout.flush() already. Not a big deal if we like that or not, but consistency would be good here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed - I'm not sure we call |
||
$timeout.flush(); | ||
} catch (err) { | ||
// This throws an error when there is nothing to flush... | ||
} | ||
}) | ||
}; | ||
|
||
arr = stubArray(STUB_DATA); | ||
}); | ||
}); | ||
|
@@ -86,8 +93,6 @@ describe('$firebaseArray', function () { | |
}); | ||
|
||
it('should resolve to ref for new record', function(done) { | ||
tick(); | ||
|
||
arr.$add({foo: 'bar'}) | ||
.then(function (ref) { | ||
expect(ref.toString()).toBe(arr.$ref().child(ref.key).toString()) | ||
|
@@ -110,7 +115,6 @@ describe('$firebaseArray', function () { | |
arr = stubArray(null, $firebaseArray.$extend({$$added:addPromise})); | ||
expect(arr.length).toBe(0); | ||
arr.$add({userId:'1234'}); | ||
//1:flushAll()(arr.$ref()); | ||
expect(arr.length).toBe(0); | ||
expect(queue.length).toBe(1); | ||
queue[0]('James'); | ||
|
@@ -139,7 +143,7 @@ describe('$firebaseArray', function () { | |
called = true; | ||
}); | ||
ref.set({'-Jwgx':{username:'James', email:'james@internet.com'}}); | ||
//1:ref.flush(); | ||
|
||
$timeout.flush(); | ||
queue[0]('James'); | ||
$timeout.flush(); | ||
|
@@ -157,8 +161,6 @@ describe('$firebaseArray', function () { | |
expect(blackSpy).toHaveBeenCalled(); | ||
done(); | ||
}); | ||
|
||
tick(); | ||
}); | ||
|
||
it('should work with a primitive value', function(done) { | ||
|
@@ -168,8 +170,6 @@ describe('$firebaseArray', function () { | |
done(); | ||
}); | ||
}); | ||
|
||
tick(); | ||
}); | ||
|
||
it('should throw error if array is destroyed', function() { | ||
|
@@ -207,16 +207,13 @@ describe('$firebaseArray', function () { | |
done(); | ||
}); | ||
}); | ||
|
||
tick(); | ||
}); | ||
|
||
it('should work on a query', function() { | ||
var ref = stubRef(); | ||
var query = ref.limitToLast(2); | ||
var arr = $firebaseArray(query); | ||
addAndProcess(arr, testutils.snap('one', 'b', 1), null); | ||
tick(); | ||
expect(arr.length).toBe(1); | ||
}); | ||
}); | ||
|
@@ -236,8 +233,6 @@ describe('$firebaseArray', function () { | |
done(); | ||
}); | ||
}); | ||
|
||
tick(); | ||
}); | ||
|
||
it('should accept an item from the array', function(done) { | ||
|
@@ -249,8 +244,6 @@ describe('$firebaseArray', function () { | |
done(); | ||
}); | ||
}); | ||
|
||
tick(); | ||
}); | ||
|
||
it('should return a promise', function() { | ||
|
@@ -264,8 +257,6 @@ describe('$firebaseArray', function () { | |
done(); | ||
}); | ||
expect(spy).not.toHaveBeenCalled(); | ||
|
||
tick(); | ||
}); | ||
|
||
it('should reject promise on failure', function(done) { | ||
|
@@ -279,8 +270,6 @@ describe('$firebaseArray', function () { | |
expect(blackSpy).toHaveBeenCalled(); | ||
done(); | ||
}); | ||
|
||
tick(); | ||
}); | ||
|
||
it('should reject promise on bad index', function(done) { | ||
|
@@ -293,9 +282,7 @@ describe('$firebaseArray', function () { | |
|
||
expect(blackSpy.calls.argsFor(0)[0]).toMatch(/invalid/i); | ||
done(); | ||
}) | ||
|
||
tick(); | ||
}); | ||
}); | ||
|
||
it('should reject promise on bad object', function(done) { | ||
|
@@ -306,8 +293,6 @@ describe('$firebaseArray', function () { | |
expect(blackSpy.calls.argsFor(0)[0]).toMatch(/invalid/i); | ||
done(); | ||
}); | ||
|
||
tick(); | ||
}); | ||
|
||
it('should accept a primitive', function() { | ||
|
@@ -319,8 +304,6 @@ describe('$firebaseArray', function () { | |
expect(ss.val()).toBe('happy'); | ||
}) | ||
}); | ||
|
||
tick(); | ||
}); | ||
|
||
it('should throw error if object is destroyed', function() { | ||
|
@@ -339,8 +322,6 @@ describe('$firebaseArray', function () { | |
expect(spy).toHaveBeenCalledWith(jasmine.objectContaining({event: 'child_changed', key: key})); | ||
done() | ||
}); | ||
|
||
$rootScope.$digest(); | ||
}); | ||
|
||
it('should work on a query', function(done) { | ||
|
@@ -353,7 +334,8 @@ describe('$firebaseArray', function () { | |
|
||
var query = ref.limitToLast(5); | ||
var arr = $firebaseArray(query); | ||
tick(function () { | ||
|
||
arr.$loaded().then(function () { | ||
var key = arr.$keyAt(1); | ||
arr[1].foo = 'watchtest'; | ||
|
||
|
@@ -362,9 +344,7 @@ describe('$firebaseArray', function () { | |
expect(blackSpy).not.toHaveBeenCalled(); | ||
done(); | ||
}); | ||
|
||
tick(); | ||
}); | ||
}) | ||
}); | ||
}); | ||
|
||
|
@@ -381,8 +361,6 @@ describe('$firebaseArray', function () { | |
done(); | ||
}); | ||
}); | ||
|
||
tick(); | ||
}); | ||
|
||
it('should return a promise', function() { | ||
|
@@ -401,8 +379,6 @@ describe('$firebaseArray', function () { | |
expect(blackSpy).not.toHaveBeenCalled(); | ||
done(); | ||
}); | ||
|
||
tick(); | ||
}); | ||
|
||
it('should reject promise on failure', function() { | ||
|
@@ -421,8 +397,6 @@ describe('$firebaseArray', function () { | |
expect(blackSpy).toHaveBeenCalledWith(err); | ||
done(); | ||
}); | ||
|
||
tick(); | ||
}); | ||
|
||
it('should reject promise if bad int', function(done) { | ||
|
@@ -435,8 +409,6 @@ describe('$firebaseArray', function () { | |
expect(blackSpy.calls.argsFor(0)[0]).toMatch(/invalid/i); | ||
done(); | ||
}); | ||
|
||
tick(); | ||
}); | ||
|
||
it('should reject promise if bad object', function() { | ||
|
@@ -449,7 +421,6 @@ describe('$firebaseArray', function () { | |
expect(blackSpy).toHaveBeenCalled(); | ||
expect(blackSpy.calls.argsFor(0)[0]).toMatch(/invalid/i); | ||
}); | ||
tick(); | ||
}); | ||
|
||
it('should work on a query', function(done) { | ||
|
@@ -465,18 +436,14 @@ describe('$firebaseArray', function () { | |
|
||
arr.$loaded() | ||
.then(function () { | ||
var p = arr.$remove(1); | ||
tick(); | ||
return p; | ||
return arr.$remove(1); | ||
}) | ||
.then(whiteSpy, blackSpy) | ||
.then(function () { | ||
expect(whiteSpy).toHaveBeenCalled(); | ||
expect(blackSpy).not.toHaveBeenCalled(); | ||
done(); | ||
}); | ||
|
||
tick(); | ||
}); | ||
|
||
it('should throw Error if array destroyed', function() { | ||
|
@@ -595,8 +562,6 @@ describe('$firebaseArray', function () { | |
expect(blackSpy).toHaveBeenCalledWith(err); | ||
done(); | ||
}); | ||
|
||
tick(); | ||
}); | ||
|
||
it('should resolve if function passed directly into $loaded', function(done) { | ||
|
@@ -622,8 +587,6 @@ describe('$firebaseArray', function () { | |
expect(whiteSpy).not.toHaveBeenCalled(); | ||
done(); | ||
}); | ||
|
||
tick(); | ||
}); | ||
}); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀🚀🚀
🔥🔥🔥