is-object-empty2 1.0.5 → 1.0.6
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.
- package/index.js +1 -1
- package/package.json +1 -1
- package/test/index.test.js +33 -0
package/index.js
CHANGED
package/package.json
CHANGED
package/test/index.test.js
CHANGED
|
@@ -95,11 +95,13 @@ describe('isObjectEmpty2', () => {
|
|
|
95
95
|
|
|
96
96
|
test('Object with multiple Symbol properties is considered non-empty', () => {
|
|
97
97
|
const obj = {};
|
|
98
|
+
|
|
98
99
|
const sym1 = Symbol('test1');
|
|
99
100
|
const sym2 = Symbol('test2');
|
|
100
101
|
|
|
101
102
|
obj[sym1] = 123;
|
|
102
103
|
obj[sym2] = 456;
|
|
104
|
+
|
|
103
105
|
expect(isObjectEmpty2(obj)).toBe(false);
|
|
104
106
|
});
|
|
105
107
|
|
|
@@ -113,8 +115,39 @@ describe('isObjectEmpty2', () => {
|
|
|
113
115
|
|
|
114
116
|
test('Object with only non-enumerable properties is considered empty', () => {
|
|
115
117
|
const obj = {};
|
|
118
|
+
|
|
116
119
|
Object.defineProperty(obj, 'prop1', { value: 1, enumerable: false });
|
|
117
120
|
Object.defineProperty(obj, 'prop2', { value: 2, enumerable: false });
|
|
121
|
+
|
|
118
122
|
expect(isObjectEmpty2(obj)).toBe(true);
|
|
119
123
|
});
|
|
124
|
+
|
|
125
|
+
test('Objects with prototype properties are considered non-empty', () => {
|
|
126
|
+
function Parent() {
|
|
127
|
+
this.inherited = 'value';
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
Parent.prototype.inheritedProp = 'prototype-value';
|
|
131
|
+
|
|
132
|
+
const child = new Parent();
|
|
133
|
+
expect(isObjectEmpty2(child)).toBe(false);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
test('Objects with getter/setter properties', () => {
|
|
137
|
+
const obj = {};
|
|
138
|
+
|
|
139
|
+
Object.defineProperty(obj, 'computed', {
|
|
140
|
+
get() { return 'value'; },
|
|
141
|
+
enumerable: true
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
expect(isObjectEmpty2(obj)).toBe(false);
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
test('Object.create(null) with enumerable properties', () => {
|
|
148
|
+
const obj = Object.create(null);
|
|
149
|
+
|
|
150
|
+
obj.a = 1;
|
|
151
|
+
expect(isObjectEmpty2(obj)).toBe(false);
|
|
152
|
+
});
|
|
120
153
|
});
|