Permalink
Browse files

add test for edge cases

  • Loading branch information...
1 parent b1637d3 commit 31b835ec8abead1da9bb1318b7d80bf63ceb7c3e @ericz ericz committed Aug 9, 2011
Showing with 58 additions and 0 deletions.
  1. +9 −0 client/public/spec/SpecHelper.js
  2. +49 −0 client/public/spec/VariableSpec.js
@@ -17,13 +17,22 @@ var SpecHelper = {
return document.getElementById(id).contentWindow;
},
+ isArray: function(someVar){
+ return Object.prototype.toString.call( someVar ) === '[object Array]';
+ },
+
deepEqual: function(a, b) {
// check object identity
if (a === b) return true;
// different types?
var atype = typeof a
var btype = typeof b;
if (atype !== btype) return false;
+ // Arrays?
+ var aarr = SpecHelper.isArray(a)
+ var barr = SpecHelper.isArray(b);
+ if (aarr !== barr) return false;
+
// basic equality test (watch out for coercions)
if (a == b) return true;
// one is falsy and the other truthy
@@ -48,6 +48,55 @@ describe("Variable Sync", function() {
});
+ it("can handle array and object sync edge cases", function() {
+
+ function setIfEqual(k, v) {
+ console.log(v, val);
+ equals = SpecHelper.deepEqual(val, v) && key === k;
+ }
+
+ var key = SpecHelper.generateRandomString();
+ var val = [];
+
+ // Create new variables
+ now[key] = val;
+
+
+ // Call server function to check if value synced
+ var equals;
+ runs(function(){
+ now.variableCheck(key, setIfEqual);
+ });
+
+ waitsFor(function(){
+ return equals;
+ }, "setting of array leaf node", 5000);
+
+ runs(function(){
+ expect(equals).toBeTruthy();
+ });
+
+ runs(function(){
+ val = {};
+ now[key] = val;
+ equals = false;
+ });
+
+
+ runs(function(){
+ now.variableCheck(key, setIfEqual);
+ });
+
+ waitsFor(function(){
+ return equals;
+ }, "setting of object leaf node", 5000);
+
+ runs(function(){
+ expect(equals).toBeTruthy();
+ });
+
+ });
+
it("can create terminal non-leaf nodes and do something with later ", function() {

0 comments on commit 31b835e

Please sign in to comment.