equals(QUnit.equiv('', false), false, "string");
equals(QUnit.equiv('', null), false, "string");
equals(QUnit.equiv('', undefined), false, "string");
-
+
// Short annotation VS new annotation
equals(QUnit.equiv(0, new Number()), true, "short annotation VS new annotation");
equals(QUnit.equiv(new Number(), 0), true, "short annotation VS new annotation");
a: [{ bat: undefined }]
}
), false);
+
+ // Objects with no prototype, created via Object.create(null), are used e.g. as dictionaries.
+ // Being able to test equivalence against object literals is quite useful.
+ if (Object.create) {
+ equals(QUnit.equiv(Object.create(null), {}), true, "empty object with no prototype VS empty object");
+
+ var nonEmptyWithNoProto = Object.create(null);
+ nonEmptyWithNoProto.foo = "bar";
+
+ equals(QUnit.equiv(nonEmptyWithNoProto, { foo: "bar" }), true, "nonempty object with no prototype VS empty object");
+ }
});
// Date, we don't need to test Date.parse() because it returns a number.
// Only test the Date instances by setting them a fix date.
// The date use is midnight January 1, 1970
-
+
var d1 = new Date();
d1.setTime(0); // fix the date
function fn2() {
return "fn2";
}
-
+
// Try to invert the order of some properties to make sure it is covered.
// It can failed when properties are compared between unsorted arrays.
equals(QUnit.equiv(
test("Instances", function() {
- function A() {}
- var a1 = new A();
- var a2 = new A();
+ function A() {}
+ var a1 = new A();
+ var a2 = new A();
function B() {
this.fn = function () {};
- }
- var b1 = new B();
- var b2 = new B();
+ }
+ var b1 = new B();
+ var b2 = new B();
equals(QUnit.equiv(a1, a2), true, "Same property, same constructor");
var b1 = new B(function () {});
var b2 = new B(function () {});
- equals(QUnit.equiv(a1, a2), true);
+ equals(QUnit.equiv(b1, b2), true);
var c1 = new C(function () {});
var c2 = new C(function () {});
circularA.abc = circularA;
circularB.abc = circularB;
equals(QUnit.equiv(circularA, circularB), true, "Should not repeat test on object (ambigous test)");
-
+
circularA.def = 1;
circularB.def = 1;
equals(QUnit.equiv(circularA, circularB), true, "Should not repeat test on object (ambigous test)");
-
+
circularA.def = 1;
circularB.def = 0;
equals(QUnit.equiv(circularA, circularB), false, "Should not repeat test on object (unambigous test)");
});
test('array with references to self wont loop', function(){
- var circularA = [],
+ var circularA = [],
circularB = [];
circularA.push(circularA);
circularB.push(circularB);
equals(QUnit.equiv(circularA, circularB), true, "Should not repeat test on array (ambigous test)");
-
+
circularA.push( 'abc' );
circularB.push( 'abc' );
equals(QUnit.equiv(circularA, circularB), true, "Should not repeat test on array (ambigous test)");
-
+
circularA.push( 'hello' );
circularB.push( 'goodbye' );
equals(QUnit.equiv(circularA, circularB), false, "Should not repeat test on array (unambigous test)");
});
test('mixed object/array with references to self wont loop', function(){
- var circularA = [{abc:null}],
+ var circularA = [{abc:null}],
circularB = [{abc:null}];
circularA[0].abc = circularA;
circularB[0].abc = circularB;
-
+
circularA.push(circularA);
circularB.push(circularB);
equals(QUnit.equiv(circularA, circularB), true, "Should not repeat test on object/array (ambigous test)");
-
+
circularA[0].def = 1;
circularB[0].def = 1;
equals(QUnit.equiv(circularA, circularB), true, "Should not repeat test on object/array (ambigous test)");
-
+
circularA[0].def = 1;
circularB[0].def = 0;
equals(QUnit.equiv(circularA, circularB), false, "Should not repeat test on object/array (unambigous test)");
});
-
test("Test that must be done at the end because they extend some primitive's prototype", function() {
// Try that a function looks like our regular expression.
// This tests if we check that a and b are really both instance of RegExp
// between RegExp and Function constructor because typeof on a RegExpt instance is "function"
equals(QUnit.equiv(function () {}, re), false, "Same conversely, but ensures that function and regexp are distinct because their constructor are different");
});
-