Skip to content
This repository was archived by the owner on Mar 17, 2025. It is now read-only.

Commit 84fd2e7

Browse files
committed
Added tests for utils.updateRec method. Abstracted some common test utilities to a module for DRY purposes.
1 parent b8ac87a commit 84fd2e7

File tree

6 files changed

+153
-144
lines changed

6 files changed

+153
-144
lines changed

tests/automatic_karma.conf.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ module.exports = function(config) {
2020
'../bower_components/lodash/dist/lodash.js',
2121
'../bower_components/angular/angular.js',
2222
'../bower_components/angular-mocks/angular-mocks.js',
23-
'lib/MockFirebase.js',
24-
'lib/jasmineMatchers.js',
23+
'lib/**/*.js',
2524
'../src/module.js',
2625
'../src/**/*.js',
2726
'mocks/**/*.js',

tests/lib/module.testutils.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
angular.module('testutils', ['firebase'])
2+
.factory('testutils', function($firebaseUtils) {
3+
var utils = {
4+
ref: function(key, base) {
5+
var ref = new MockFirebase().child(base||'data');
6+
if( key ) { ref = ref.child(key); }
7+
return ref;
8+
},
9+
10+
deepCopyObject: function(obj) {
11+
var newCopy = angular.isArray(obj) ? obj.slice() : angular.extend({}, obj);
12+
for (var key in newCopy) {
13+
if (newCopy.hasOwnProperty(key)) {
14+
if (angular.isObject(newCopy[key])) {
15+
newCopy[key] = utils.deepCopyObject(newCopy[key]);
16+
}
17+
}
18+
}
19+
return newCopy;
20+
},
21+
22+
snap: function(data, refKey, pri) {
23+
return utils.refSnap(utils.ref(refKey), data, pri);
24+
},
25+
26+
refSnap: function(ref, data, pri) {
27+
data = copySnapData(data);
28+
return {
29+
ref: function () {
30+
return ref;
31+
},
32+
val: function () {
33+
return data;
34+
},
35+
getPriority: function () {
36+
return angular.isDefined(pri) ? pri : null;
37+
},
38+
name: function () {
39+
return ref.ref().name();
40+
},
41+
child: function (key) {
42+
var childData = angular.isObject(data) && data.hasOwnProperty(key) ? data[key] : null;
43+
return utils.fakeSnap(ref.child(key), childData, null);
44+
}
45+
}
46+
}
47+
};
48+
49+
function copySnapData(obj) {
50+
if (!angular.isObject(obj)) {
51+
return obj;
52+
}
53+
var copy = {};
54+
$firebaseUtils.each(obj, function (v, k) {
55+
copy[k] = angular.isObject(v) ? utils.deepCopyObject(v) : v;
56+
});
57+
return copy;
58+
}
59+
60+
return utils;
61+
});

tests/sauce_karma.conf.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ module.exports = function(config) {
2121
'../bower_components/angular/angular.js',
2222
'../bower_components/angular-mocks/angular-mocks.js',
2323
'../bower_components/lodash/dist/lodash.js',
24-
'lib/MockFirebase.js',
24+
'lib/**/*.js',
2525
'../dist/angularfire.js',
26+
'mocks/**/*.js',
2627
'unit/**/*.spec.js'
2728
],
2829

0 commit comments

Comments
 (0)