Skip to content

Commit bc1f07b

Browse files
committed
capture correct value, add tests
1 parent 8ef39cc commit bc1f07b

File tree

2 files changed

+53
-22
lines changed

2 files changed

+53
-22
lines changed

packages/utils/src/object.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ function getWalkSource(
133133

134134
for (const i in event) {
135135
if (Object.prototype.hasOwnProperty.call(event, i)) {
136-
source[i] = event;
136+
source[i] = event[i];
137137
}
138138
}
139139

packages/utils/test/object.test.ts

Lines changed: 52 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/**
2+
* @jest-environment jsdom
3+
*/
4+
5+
import * as isModule from '../src/is';
16
import { dropUndefinedKeys, extractExceptionKeysForMessage, fill, normalize, urlEncode } from '../src/object';
27

38
describe('fill()', () => {
@@ -119,28 +124,54 @@ describe('normalize()', () => {
119124
});
120125
});
121126

122-
test('extracts extra properties from error objects', () => {
123-
const obj = new Error('Wubba Lubba Dub Dub') as any;
124-
obj.reason = new TypeError("I'm pickle Riiick!");
125-
obj.extra = 'some extra prop';
126-
127-
obj.stack = 'x';
128-
obj.reason.stack = 'x';
129-
130-
// IE 10/11
131-
delete obj.description;
132-
delete obj.reason.description;
133-
134-
expect(normalize(obj)).toEqual({
135-
message: 'Wubba Lubba Dub Dub',
136-
name: 'Error',
137-
stack: 'x',
138-
reason: {
139-
message: "I'm pickle Riiick!",
140-
name: 'TypeError',
127+
describe('getWalkSource()', () => {
128+
test('extracts extra properties from error objects', () => {
129+
const obj = new Error('Wubba Lubba Dub Dub') as any;
130+
obj.reason = new TypeError("I'm pickle Riiick!");
131+
obj.extra = 'some extra prop';
132+
133+
obj.stack = 'x';
134+
obj.reason.stack = 'x';
135+
136+
// IE 10/11
137+
delete obj.description;
138+
delete obj.reason.description;
139+
140+
expect(normalize(obj)).toEqual({
141+
message: 'Wubba Lubba Dub Dub',
142+
name: 'Error',
141143
stack: 'x',
142-
},
143-
extra: 'some extra prop',
144+
reason: {
145+
message: "I'm pickle Riiick!",
146+
name: 'TypeError',
147+
stack: 'x',
148+
},
149+
extra: 'some extra prop',
150+
});
151+
});
152+
153+
test('extracts data from `Event` objects', () => {
154+
const isElement = jest.spyOn(isModule, 'isElement').mockReturnValue(true);
155+
const getAttribute = () => undefined;
156+
157+
const parkElement = { tagName: 'PARK', getAttribute };
158+
const treeElement = { tagName: 'TREE', parentNode: parkElement, getAttribute };
159+
const squirrelElement = { tagName: 'SQUIRREL', parentNode: treeElement, getAttribute };
160+
161+
const chaseEvent = new Event('chase');
162+
Object.defineProperty(chaseEvent, 'target', { value: squirrelElement });
163+
Object.defineProperty(chaseEvent, 'currentTarget', { value: parkElement });
164+
Object.defineProperty(chaseEvent, 'wagging', { value: true, enumerable: false });
165+
166+
expect(normalize(chaseEvent)).toEqual({
167+
currentTarget: 'park',
168+
isTrusted: false,
169+
target: 'park > tree > squirrel',
170+
type: 'chase',
171+
// notice that `wagging` isn't included because it's not enumerable and not one of the ones we specifically extract
172+
});
173+
174+
isElement.mockRestore();
144175
});
145176
});
146177

0 commit comments

Comments
 (0)