@webfactoryde/merge-objects 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,7 +2,7 @@ name: Tests
2
2
 
3
3
  on:
4
4
  push:
5
- branches: [ master ]
5
+ branches: [ main ]
6
6
  pull_request:
7
7
  pull_request_target:
8
8
 
package/jest.config.js CHANGED
@@ -1,5 +1,5 @@
1
1
  export default {
2
- testEnvironment: 'node',
2
+ testEnvironment: 'jsdom',
3
3
  transform: {
4
4
  '^.+\\.jsx?$': 'babel-jest', // Use Babel to transpile ES modules
5
5
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webfactoryde/merge-objects",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "JS Utility that merges multiple objects into one, with an option for deep merging",
5
5
  "main": "src/merge-objects.js",
6
6
  "type": "module",
@@ -8,7 +8,8 @@
8
8
  "@babel/core": "^7.28.3",
9
9
  "@babel/preset-env": "^7.28.3",
10
10
  "babel-jest": "^30.1.1",
11
- "jest": "^30.1.0"
11
+ "jest": "^30.1.0",
12
+ "jest-environment-jsdom": "^30.2.0"
12
13
  },
13
14
  "scripts": {
14
15
  "test": "jest"
@@ -32,7 +32,7 @@ export default function mergeObjects(...args) {
32
32
  const merge = (obj) => {
33
33
  for (const prop in obj) {
34
34
  if (Object.prototype.hasOwnProperty.call(obj, prop)) {
35
- if (deep && typeof obj[prop] === 'object' && obj[prop] !== null) {
35
+ if (deep && Object.prototype.toString.call(obj[prop]) === '[object Object]') {
36
36
  extended[prop] = mergeObjects(true, extended[prop] || {}, obj[prop]);
37
37
  } else {
38
38
  extended[prop] = obj[prop];
@@ -37,10 +37,11 @@ describe('mergeObjects', () => {
37
37
  });
38
38
 
39
39
  test('should handle empty objects', () => {
40
- const obj1 = {};
40
+ const obj1 = { a: 1 };
41
41
  const obj2 = {};
42
- const result = mergeObjects(false, obj1, obj2);
43
- expect(result).toEqual({});
42
+ const obj3 = { c: 3 };
43
+ const result = mergeObjects(false, obj1, obj2, obj3);
44
+ expect(result).toEqual({ a: 1, c: 3 });
44
45
  });
45
46
 
46
47
  test('should handle deep merge with empty objects', () => {
@@ -49,4 +50,16 @@ describe('mergeObjects', () => {
49
50
  const result = mergeObjects(true, obj1, obj2);
50
51
  expect(result).toEqual({ a: 1, b: { y: 30 }, c: 4 });
51
52
  });
53
+
54
+ test('should preserve DOM element references in deep merge', () => {
55
+ const div = document.createElement('div');
56
+ div.id = 'test';
57
+
58
+ const obj1 = {};
59
+ const obj2 = { element: div };
60
+ const result = mergeObjects(true, obj1, obj2);
61
+
62
+ expect(result.element).toBe(div);
63
+ expect(result.element.id).toBe('test');
64
+ });
52
65
  });