Browse Source

address review comments, make the unittest code more readable

Lei Shi 9 years ago
parent
commit
614057f49f
1 changed files with 24 additions and 26 deletions
  1. 24 26
      test/es7/lookupgettersetter.js

+ 24 - 26
test/es7/lookupgettersetter.js

@@ -9,39 +9,37 @@ var tests = [
     {
         name: "Object.prototype.__lookupGetter__ -> [[GetOwnProperty]], [[GetPrototypeOf]]",
         body: function () {
-            assert.isTrue((function()
+            // Object.prototype.__lookupGetter__ -> [[GetOwnProperty]]
+            // Object.prototype.__lookupGetter__ -> [[GetPrototypeOf]]
+            var gopd = [];
+            var gpo = false;
+            var p = new Proxy({}, 
             {
-                // Object.prototype.__lookupGetter__ -> [[GetOwnProperty]]
-                // Object.prototype.__lookupGetter__ -> [[GetPrototypeOf]]
-                var gopd = [];
-                var gpo = false;
-                var p = new Proxy({}, 
-                {
-                    getPrototypeOf: function(o) { gpo = true; return Object.getPrototypeOf(o); },
-                    getOwnPropertyDescriptor: function(o, v) { gopd.push(v); return Object.getOwnPropertyDescriptor(o, v); }
-                });
-                Object.prototype.__lookupGetter__.call(p, "foo");
-                return gopd + '' === "foo" && gpo;
-            })());
+                getPrototypeOf: function(o) { gpo = true; return Object.getPrototypeOf(o); },
+                getOwnPropertyDescriptor: function(o, v) { gopd.push(v); return Object.getOwnPropertyDescriptor(o, v); }
+            });
+            Object.prototype.__lookupGetter__.call(p, "foo");
+            assert.areEqual(1, gopd.length, "getOwnPropertyDescriptor should only be called once");
+            assert.areEqual("foo", gopd[0], "getOwnPropertyDescriptor should be called with foo");
+            assert.isTrue(gpo, "getPrototypeOf should be called");
         }
     },
     {
         name: "Object.prototype.__lookupSetter__ -> [[GetOwnProperty]], [[GetPrototypeOf]]",
         body: function () {
-            assert.isTrue((function()
+            // Object.prototype.__lookupSetter__ -> [[GetOwnProperty]]
+            // Object.prototype.__lookupSetter__ -> [[GetPrototypeOf]]
+            var gopd = [];
+            var gpo = false;
+            var p = new Proxy({}, 
             {
-                // Object.prototype.__lookupSetter__ -> [[GetOwnProperty]]
-                // Object.prototype.__lookupSetter__ -> [[GetPrototypeOf]]
-                var gopd = [];
-                var gpo = false;
-                var p = new Proxy({}, 
-                {
-                    getPrototypeOf: function(o) { gpo = true; return Object.getPrototypeOf(o); },
-                    getOwnPropertyDescriptor: function(o, v) { gopd.push(v); return Object.getOwnPropertyDescriptor(o, v); }
-                });
-                Object.prototype.__lookupSetter__.call(p, "foo");
-                return gopd + '' === "foo" && gpo;
-            })());
+                getPrototypeOf: function(o) { gpo = true; return Object.getPrototypeOf(o); },
+                getOwnPropertyDescriptor: function(o, v) { gopd.push(v); return Object.getOwnPropertyDescriptor(o, v); }
+            });
+            Object.prototype.__lookupSetter__.call(p, "foo");
+            assert.areEqual(1, gopd.length, "getOwnPropertyDescriptor should only be called once");
+            assert.areEqual("foo", gopd[0], "getOwnPropertyDescriptor should be called with foo");
+            assert.isTrue(gpo, "getPrototypeOf should be called");
         }
     }
 ];