Skip to content

Commit 73a5c00

Browse files
committed
test: Add tests to decycle non-enum props
1 parent 587b8f3 commit 73a5c00

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed

CHANGELOG.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22

33
## Unreleased
44

5-
- [browser] fix: DOMError and DOMException should be error level events
6-
- [utils] fix: Dont mutate original input in decycle util function
7-
- [utils] ref: Update wrap method to hide internal sentry flags
8-
- [utils] fix: Make internal Sentry flags non-enumerable in fill util
5+
- [browser] fix: `DOMError` and `DOMException` should be error level events
6+
- [utils] fix: Dont mutate original input in `decycle` util function
7+
- [utils] fix: Skip non-enumerable properties in `decycle` util function
8+
- [utils] ref: Update `wrap` method to hide internal Sentry flags
9+
- [utils] fix: Make internal Sentry flags non-enumerable in `fill` util
910

1011
## 4.5.3
1112

packages/utils/src/object.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ export function decycle(obj: any, memo: Memo = new Memo()): any {
336336
// tslint:disable-next-line
337337
for (const key in obj) {
338338
// Avoid iterating over fields in the prototype if they've somehow been exposed to enumeration.
339-
if (!obj.hasOwnProperty(key)) {
339+
if (!Object.prototype.hasOwnProperty.call(obj, key)) {
340340
continue;
341341
}
342342
// tslint:disable-next-line

packages/utils/test/object.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,29 @@ describe('decycle()', () => {
113113
expect(circular.qux).toBe(circular.bar[0].baz);
114114
expect(decycled).not.toBe(circular);
115115
});
116+
117+
test('skip non-enumerable properties', () => {
118+
const circular = {
119+
foo: 1,
120+
};
121+
circular.bar = circular;
122+
Object.defineProperty(circular, 'baz', {
123+
enumerable: true,
124+
value: circular
125+
});
126+
Object.defineProperty(circular, 'qux', {
127+
enumerable: false,
128+
value: circular
129+
});
130+
131+
const decycled = decycle(circular);
132+
133+
expect(decycled).toEqual({
134+
bar: '[Circular ~]',
135+
baz: '[Circular ~]',
136+
foo: 1,
137+
});
138+
});
116139
});
117140

118141
describe('serialize()', () => {

0 commit comments

Comments
 (0)