-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathisDeepEqual.tests.ts
202 lines (121 loc) · 4.26 KB
/
isDeepEqual.tests.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
import { isDeepEqual } from "../src/isDeepEqual"
describe("Comparing simple types", () => {
test("Comparing equal numbers should return true", () => {
const left = 10
const right = 10
const res = isDeepEqual(left, right)
expect(res).toBe(true)
})
test("Comparing different numbers should return false", () => {
const left = 10
const right = 10
const res = isDeepEqual(left, right)
expect(res).toBe(true)
})
test("Comparing equal strings should return true", () => {
const left = "hello"
const right = "hello"
const res = isDeepEqual(left, right)
expect(res).toBe(true)
})
test("Comparing different strings should return false", () => {
const left = "hello"
const right = "goodbye"
const res = isDeepEqual(left, right)
expect(res).toBe(false)
})
})
describe("Comparisson of nulls and undefineds", () => {
test("Comparing two undefineds should return true", () => {
const left = undefined
const right = undefined
const res = isDeepEqual(left, right)
expect(res).toBe(true)
})
test("Comparing two nulls should return true", () => {
const left = null
const right = null
const res = isDeepEqual(left, right)
expect(res).toBe(true)
})
test("Comparing undefined to null should return false", () => {
const left = undefined
const right = null
const res = isDeepEqual(left, right)
expect(res).toBe(false)
})
test("Comparing undefined to anything not undefined should return false", () => {
const left = undefined
const right = 42
const res = isDeepEqual(left, right)
expect(res).toBe(false)
})
test("Comparing null to anything not null should return false", () => {
const left = null
const right = 42
const res = isDeepEqual(left, right)
expect(res).toBe(false)
})
})
describe("Object comparisson", () => {
test("Comparing similar objects with same values should return true", () => {
const left = { a: 10 }
const right = { a: 10 }
const res = isDeepEqual(left, right)
expect(res).toBe(true)
})
test("Comparing similar objects with different values should return false", () => {
const left = { a: 10 }
const right = { a: 11 }
const res = isDeepEqual(left, right)
expect(res).toBe(false)
})
test("Comparing similar deep objects with same values should return true", () => {
const left = { b: { c: 20}}
const right = { b: { c: 20}}
const res = isDeepEqual(left, right)
expect(res).toBe(true)
})
test("Comparing similar deep objects with different values should return true", () => {
const left = { b: { c: 20}}
const right = { b: { c: 21}}
const res = isDeepEqual(left, right)
expect(res).toBe(false)
})
test("Comparing different objects should return false", () => {
const left = { a: 10 } as unknown
const right = { b: 10 } as unknown
const res = isDeepEqual(left, right)
expect(res).toBe(false)
})
})
describe("Array comparisson", () => {
test("Comparing to identical arrays return true", () => {
const left = [10, 20]
const right = [10, 20]
const res = isDeepEqual(left, right)
expect(res).toBe(true)
})
test("Comparing similar arrays with different ordered, but same values should return true", () => {
const left = [10, 20]
const right = [20, 10]
const res = isDeepEqual(left, right)
expect(res).toBe(false)
})
test("Comparing to different arrays return false", () => {
const left = [10, 20]
const right = [10, 21]
const res = isDeepEqual(left, right)
expect(res).toBe(false)
})
})
describe("Other special cases...", () => {
test("Comparing object with different prototypes returns false", () => {
const left = Object.create({b:10})
left.a = 10
const right = Object.create({})
left.a = 10
const res = isDeepEqual(left, right)
expect(res).toBe(false)
})
})