mirror of
https://github.com/theoludwig/theoludwig.git
synced 2025-05-29 22:37:44 +02:00
build: update to Node.js v24.0.0, pnpm v10, Tailwind CSS v4
This commit is contained in:
85
packages/utils/src/test/objects.test.ts
Normal file
85
packages/utils/src/test/objects.test.ts
Normal file
@ -0,0 +1,85 @@
|
||||
import assert from "node:assert/strict"
|
||||
import { describe, it } from "node:test"
|
||||
import { deepMerge } from "../objects.ts"
|
||||
|
||||
describe("objects", () => {
|
||||
describe("deepMerge", () => {
|
||||
it("should merge two simple objects", () => {
|
||||
// Arrange - Given
|
||||
const object1 = { a: 1, b: 2 }
|
||||
const object2 = { b: 3, c: 4 }
|
||||
|
||||
// Act - When
|
||||
const output = deepMerge(object1, object2)
|
||||
|
||||
// Assert - Then
|
||||
const expected = { a: 1, b: 3, c: 4 }
|
||||
assert.deepStrictEqual(output, expected)
|
||||
})
|
||||
|
||||
it("should deeply merge nested objects", () => {
|
||||
// Arrange - Given
|
||||
const object1 = { a: 1, b: { x: 2, y: 3 } }
|
||||
const object2 = { b: { y: 4, z: 5 }, c: 6 }
|
||||
|
||||
// Act - When
|
||||
const output = deepMerge(object1, object2)
|
||||
|
||||
// Assert - Then
|
||||
const expected = { a: 1, b: { x: 2, y: 4, z: 5 }, c: 6 }
|
||||
assert.deepStrictEqual(output, expected)
|
||||
})
|
||||
|
||||
it("should overwrite primitive values", () => {
|
||||
// Arrange - Given
|
||||
const object1 = { a: 1, b: "hello" }
|
||||
const object2 = { a: 2, b: "world" }
|
||||
|
||||
// Act - When
|
||||
const output = deepMerge(object1, object2)
|
||||
|
||||
// Assert - Then
|
||||
const expected = { a: 2, b: "world" }
|
||||
assert.deepStrictEqual(output, expected)
|
||||
})
|
||||
|
||||
it("should return the second object if the first is empty", () => {
|
||||
// Arrange - Given
|
||||
const object1 = {}
|
||||
const object2 = { a: 1, b: 2 }
|
||||
|
||||
// Act - When
|
||||
const output = deepMerge(object1, object2)
|
||||
|
||||
// Assert - Then
|
||||
const expected = { a: 1, b: 2 }
|
||||
assert.deepStrictEqual(output, expected)
|
||||
})
|
||||
|
||||
it("should return the first object if the second is empty", () => {
|
||||
// Arrange - Given
|
||||
const object1 = { a: 1, b: 2 }
|
||||
const object2 = {}
|
||||
|
||||
// Act - When
|
||||
const output = deepMerge(object1, object2)
|
||||
|
||||
// Assert - Then
|
||||
const expected = { a: 1, b: 2 }
|
||||
assert.deepStrictEqual(output, expected)
|
||||
})
|
||||
|
||||
it("should handle null and undefined values correctly", () => {
|
||||
// Arrange - Given
|
||||
const object1 = { a: 1, b: null }
|
||||
const object2 = { b: { c: 2 }, d: undefined }
|
||||
|
||||
// Act - When
|
||||
const output = deepMerge(object1, object2)
|
||||
|
||||
// Assert - Then
|
||||
const expected = { a: 1, b: { c: 2 }, d: undefined }
|
||||
assert.deepStrictEqual(output, expected)
|
||||
})
|
||||
})
|
||||
})
|
Reference in New Issue
Block a user