@@ -12,14 +12,18 @@ describe('Equality', () => {
12
12
13
13
function expectIs ( left , right ) {
14
14
var comparison = Immutable . is ( left , right ) ;
15
+ expect ( comparison ) . toBe ( true ) ;
15
16
var commutative = Immutable . is ( right , left ) ;
16
- return comparison && commutative && comparison === commutative ;
17
+ expect ( commutative ) . toBe ( true ) ;
18
+ expect ( comparison === commutative ) . toBe ( true ) ;
17
19
}
18
20
19
21
function expectIsNot ( left , right ) {
20
22
var comparison = Immutable . is ( left , right ) ;
23
+ expect ( comparison ) . toBe ( false ) ;
21
24
var commutative = Immutable . is ( right , left ) ;
22
- return ! comparison && ! commutative && comparison === commutative ;
25
+ expect ( commutative ) . toBe ( false ) ;
26
+ expect ( comparison === commutative ) . toBe ( true ) ;
23
27
}
24
28
25
29
it ( 'uses Object.is semantics' , ( ) => {
@@ -36,7 +40,9 @@ describe('Equality', () => {
36
40
expectIs ( NaN , NaN ) ;
37
41
expectIs ( 0 , 0 ) ;
38
42
expectIs ( - 0 , - 0 ) ;
39
- expectIsNot ( 0 , - 0 ) ;
43
+ // Note: Unlike Object.is, Immutable.is assumes 0 and -0 are the same value,
44
+ // matching the behavior of ES6 Map key equality.
45
+ expectIs ( 0 , - 0 ) ;
40
46
expectIs ( NaN , 0 / 0 ) ;
41
47
42
48
var string = "hello" ;
@@ -54,6 +60,35 @@ describe('Equality', () => {
54
60
expectIsNot ( object , { key :'value' } ) ;
55
61
} ) ;
56
62
63
+ it ( 'dereferences things' , ( ) => {
64
+ var ptrA = { foo : 1 } , ptrB = { foo : 2 } ;
65
+ expectIsNot ( ptrA , ptrB ) ;
66
+ ptrA . valueOf = ptrB . valueOf = function ( ) {
67
+ return 5 ;
68
+ }
69
+ expectIs ( ptrA , ptrB ) ;
70
+ var object = { key :'value' } ;
71
+ ptrA . valueOf = ptrB . valueOf = function ( ) {
72
+ return object ;
73
+ }
74
+ expectIs ( ptrA , ptrB ) ;
75
+ ptrA . valueOf = ptrB . valueOf = function ( ) {
76
+ return null ;
77
+ }
78
+ expectIs ( ptrA , ptrB ) ;
79
+ ptrA . valueOf = ptrB . valueOf = function ( ) {
80
+ return void 0 ;
81
+ }
82
+ expectIs ( ptrA , ptrB ) ;
83
+ ptrA . valueOf = function ( ) {
84
+ return 4 ;
85
+ }
86
+ ptrB . valueOf = function ( ) {
87
+ return 5 ;
<
8000
/td>
88
+ }
89
+ expectIsNot ( ptrA , ptrB ) ;
90
+ } ) ;
91
+
57
92
it ( 'compares sequences' , ( ) => {
58
93
var arraySeq = Immutable . Seq . of ( 1 , 2 , 3 ) ;
59
94
var arraySeq2 = Immutable . Seq ( [ 1 , 2 , 3 ] ) ;
0 commit comments