Skip to content

Commit 7e1a554

Browse files
test: deepEqual()
1 parent 54f06b5 commit 7e1a554

File tree

1 file changed

+106
-1
lines changed

1 file changed

+106
-1
lines changed

src/test/utils.spec.js

+106-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { debounce, computeTooltipPosition, cssTimeToMs } from 'utils'
1+
import { debounce, deepEqual, computeTooltipPosition, cssTimeToMs } from 'utils'
22

33
describe('compute positions', () => {
44
test('empty reference elements', async () => {
@@ -151,3 +151,108 @@ describe('debounce', () => {
151151
expect(func).not.toHaveBeenCalled()
152152
})
153153
})
154+
155+
describe('deepEqual', () => {
156+
test('returns true for equal primitives', () => {
157+
expect(deepEqual(1, 1)).toBe(true)
158+
expect(deepEqual('a', 'a')).toBe(true)
159+
expect(deepEqual(true, true)).toBe(true)
160+
})
161+
162+
test('returns false for different primitives', () => {
163+
expect(deepEqual(1, 2)).toBe(false)
164+
expect(deepEqual('a', 'b')).toBe(false)
165+
expect(deepEqual(true, false)).toBe(false)
166+
})
167+
168+
test('returns true for equal objects', () => {
169+
const obj1 = { a: 1, b: 2 }
170+
const obj2 = { a: 1, b: 2 }
171+
172+
expect(deepEqual(obj1, obj2)).toBe(true)
173+
})
174+
175+
test('returns false for different objects', () => {
176+
const obj1 = { a: 1, b: 2 }
177+
const obj2 = { a: 1, b: 3 }
178+
179+
expect(deepEqual(obj1, obj2)).toBe(false)
180+
})
181+
182+
test('returns false for object with different amount of keys', () => {
183+
const obj1 = { a: 1, b: 2 }
184+
const obj2 = { a: 1 }
185+
186+
expect(deepEqual(obj1, obj2)).toBe(false)
187+
})
188+
189+
test('returns true for equal nested objects', () => {
190+
const obj1 = { a: 1, b: { c: 2, d: 3 } }
191+
const obj2 = { a: 1, b: { c: 2, d: 3 } }
192+
193+
expect(deepEqual(obj1, obj2)).toBe(true)
194+
})
195+
196+
test('returns false for different nested objects', () => {
197+
const obj1 = { a: 1, b: { c: 2, d: 3 } }
198+
const obj2 = { a: 1, b: { c: 2, d: 4 } }
199+
200+
expect(deepEqual(obj1, obj2)).toBe(false)
201+
})
202+
203+
test('returns true for equal arrays', () => {
204+
const obj1 = [1, 2, 3]
205+
const obj2 = [1, 2, 3]
206+
207+
expect(deepEqual(obj1, obj2)).toBe(true)
208+
})
209+
210+
test('returns false for different arrays', () => {
211+
const obj1 = [1, 2, 3]
212+
const obj2 = [1, 2, 4]
213+
214+
expect(deepEqual(obj1, obj2)).toBe(false)
215+
})
216+
217+
test('returns false for different length arrays', () => {
218+
const obj1 = [1, 2, 3]
219+
const obj2 = [1, 2]
220+
221+
expect(deepEqual(obj1, obj2)).toBe(false)
222+
})
223+
224+
test('returns false for array with non-array', () => {
225+
const obj1 = [1, 2, 3]
226+
const obj2 = 1
227+
228+
expect(deepEqual(obj1, obj2)).toBe(false)
229+
})
230+
231+
test('returns true for equal nested arrays', () => {
232+
const obj1 = [1, [2, 3]]
233+
const obj2 = [1, [2, 3]]
234+
235+
expect(deepEqual(obj1, obj2)).toBe(true)
236+
})
237+
238+
test('returns false for different nested arrays', () => {
239+
const obj1 = [1, [2, 3]]
240+
const obj2 = [1, [2, 4]]
241+
242+
expect(deepEqual(obj1, obj2)).toBe(false)
243+
})
244+
245+
test('returns true for equal mixed objects and arrays', () => {
246+
const obj1 = { a: 1, b: [2, 3] }
247+
const obj2 = { a: 1, b: [2, 3] }
248+
249+
expect(deepEqual(obj1, obj2)).toBe(true)
250+
})
251+
252+
test('returns false for different mixed objects and arrays', () => {
253+
const obj1 = { a: 1, b: [2, 3] }
254+
const obj2 = { a: 1, b: [2, 4] }
255+
256+
expect(deepEqual(obj1, obj2)).toBe(false)
257+
})
258+
})

0 commit comments

Comments
 (0)