Skip to content

Commit

Permalink
test: deepEqual()
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrieljablonski committed Feb 18, 2024
1 parent 54f06b5 commit 7e1a554
Showing 1 changed file with 106 additions and 1 deletion.
107 changes: 106 additions & 1 deletion src/test/utils.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { debounce, computeTooltipPosition, cssTimeToMs } from 'utils'
import { debounce, deepEqual, computeTooltipPosition, cssTimeToMs } from 'utils'

describe('compute positions', () => {
test('empty reference elements', async () => {
Expand Down Expand Up @@ -151,3 +151,108 @@ describe('debounce', () => {
expect(func).not.toHaveBeenCalled()
})
})

describe('deepEqual', () => {
test('returns true for equal primitives', () => {
expect(deepEqual(1, 1)).toBe(true)
expect(deepEqual('a', 'a')).toBe(true)
expect(deepEqual(true, true)).toBe(true)
})

test('returns false for different primitives', () => {
expect(deepEqual(1, 2)).toBe(false)
expect(deepEqual('a', 'b')).toBe(false)
expect(deepEqual(true, false)).toBe(false)
})

test('returns true for equal objects', () => {
const obj1 = { a: 1, b: 2 }
const obj2 = { a: 1, b: 2 }

expect(deepEqual(obj1, obj2)).toBe(true)
})

test('returns false for different objects', () => {
const obj1 = { a: 1, b: 2 }
const obj2 = { a: 1, b: 3 }

expect(deepEqual(obj1, obj2)).toBe(false)
})

test('returns false for object with different amount of keys', () => {
const obj1 = { a: 1, b: 2 }
const obj2 = { a: 1 }

expect(deepEqual(obj1, obj2)).toBe(false)
})

test('returns true for equal nested objects', () => {
const obj1 = { a: 1, b: { c: 2, d: 3 } }
const obj2 = { a: 1, b: { c: 2, d: 3 } }

expect(deepEqual(obj1, obj2)).toBe(true)
})

test('returns false for different nested objects', () => {
const obj1 = { a: 1, b: { c: 2, d: 3 } }
const obj2 = { a: 1, b: { c: 2, d: 4 } }

expect(deepEqual(obj1, obj2)).toBe(false)
})

test('returns true for equal arrays', () => {
const obj1 = [1, 2, 3]
const obj2 = [1, 2, 3]

expect(deepEqual(obj1, obj2)).toBe(true)
})

test('returns false for different arrays', () => {
const obj1 = [1, 2, 3]
const obj2 = [1, 2, 4]

expect(deepEqual(obj1, obj2)).toBe(false)
})

test('returns false for different length arrays', () => {
const obj1 = [1, 2, 3]
const obj2 = [1, 2]

expect(deepEqual(obj1, obj2)).toBe(false)
})

test('returns false for array with non-array', () => {
const obj1 = [1, 2, 3]
const obj2 = 1

expect(deepEqual(obj1, obj2)).toBe(false)
})

test('returns true for equal nested arrays', () => {
const obj1 = [1, [2, 3]]
const obj2 = [1, [2, 3]]

expect(deepEqual(obj1, obj2)).toBe(true)
})

test('returns false for different nested arrays', () => {
const obj1 = [1, [2, 3]]
const obj2 = [1, [2, 4]]

expect(deepEqual(obj1, obj2)).toBe(false)
})

test('returns true for equal mixed objects and arrays', () => {
const obj1 = { a: 1, b: [2, 3] }
const obj2 = { a: 1, b: [2, 3] }

expect(deepEqual(obj1, obj2)).toBe(true)
})

test('returns false for different mixed objects and arrays', () => {
const obj1 = { a: 1, b: [2, 3] }
const obj2 = { a: 1, b: [2, 4] }

expect(deepEqual(obj1, obj2)).toBe(false)
})
})

0 comments on commit 7e1a554

Please sign in to comment.