fixed an unit test to work in older browsers. popcorn-port
authorhamidouk
Wed, 26 Oct 2011 17:21:35 +0200
branchpopcorn-port
changeset 156 0e6a4d1e4dbe
parent 155 0ee6d3dd57d1
child 157 73bce42a3ed3
fixed an unit test to work in older browsers.
unittests/tests/JSONSerializer.js
--- a/unittests/tests/JSONSerializer.js	Wed Oct 26 16:39:52 2011 +0200
+++ b/unittests/tests/JSONSerializer.js	Wed Oct 26 17:21:35 2011 +0200
@@ -120,12 +120,21 @@
         "title": "sans titre"
       }, "id" : 4}
       ]};
-            
-      // warning : these tests may not work with ie8, safari 4, etc.      
-      equal(Object.keys(ser.searchOccurences("garrigou")).length, 1, "first request works");
+      
+      // a function to get the number of fields in a dict.
+      function countOccurences(queryString) {
+        var count = 0;
+        for (var i in ser.searchOccurences(queryString)) {
+          count++;
+        };
+        
+        return count;
+      };
+      
+      equal(countOccurences("garrigou"), 1, "first request works");
       deepEqual(ser.searchOccurences("garrigou"), {1 : 1}, "returned object is correctly defined");
-      
-      equal(Object.keys(ser.searchOccurences("garrigou interview")).length, 2, "second request works");
-      equal(Object.keys(ser.searchOccurences("garrigou idée interview")).length, 3, "third request works");
+          
+      equal(countOccurences("garrigou interview"), 2, "second request works");
+      equal(countOccurences("garrigou idée interview"), 3, "third request works");
     });
 };
\ No newline at end of file