|
| 1 | +/** |
| 2 | + * @jest-environment jsdom |
| 3 | + */ |
| 4 | + |
| 5 | +import * as isModule from '../src/is'; |
1 | 6 | import { dropUndefinedKeys, extractExceptionKeysForMessage, fill, normalize, urlEncode } from '../src/object'; |
| 7 | +import { testOnlyIfNodeVersionAtLeast } from './testutils'; |
2 | 8 |
|
3 | 9 | describe('fill()', () => { |
4 | 10 | test('wraps a method by calling a replacement function on it', () => { |
@@ -119,28 +125,54 @@ describe('normalize()', () => { |
119 | 125 | }); |
120 | 126 | }); |
121 | 127 |
|
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', |
| 128 | + describe('getWalkSource()', () => { |
| 129 | + test('extracts extra properties from error objects', () => { |
| 130 | + const obj = new Error('Wubba Lubba Dub Dub') as any; |
| 131 | + obj.reason = new TypeError("I'm pickle Riiick!"); |
| 132 | + obj.extra = 'some extra prop'; |
| 133 | + |
| 134 | + obj.stack = 'x'; |
| 135 | + obj.reason.stack = 'x'; |
| 136 | + |
| 137 | + // IE 10/11 |
| 138 | + delete obj.description; |
| 139 | + delete obj.reason.description; |
| 140 | + |
| 141 | + expect(normalize(obj)).toEqual({ |
| 142 | + message: 'Wubba Lubba Dub Dub', |
| 143 | + name: 'Error', |
141 | 144 | stack: 'x', |
142 | | - }, |
143 | | - extra: 'some extra prop', |
| 145 | + reason: { |
| 146 | + message: "I'm pickle Riiick!", |
| 147 | + name: 'TypeError', |
| 148 | + stack: 'x', |
| 149 | + }, |
| 150 | + extra: 'some extra prop', |
| 151 | + }); |
| 152 | + }); |
| 153 | + |
| 154 | + testOnlyIfNodeVersionAtLeast(8)('extracts data from `Event` objects', () => { |
| 155 | + const isElement = jest.spyOn(isModule, 'isElement').mockReturnValue(true); |
| 156 | + const getAttribute = () => undefined; |
| 157 | + |
| 158 | + const parkElement = { tagName: 'PARK', getAttribute }; |
| 159 | + const treeElement = { tagName: 'TREE', parentNode: parkElement, getAttribute }; |
| 160 | + const squirrelElement = { tagName: 'SQUIRREL', parentNode: treeElement, getAttribute }; |
| 161 | + |
| 162 | + const chaseEvent = new Event('chase'); |
| 163 | + Object.defineProperty(chaseEvent, 'target', { value: squirrelElement }); |
| 164 | + Object.defineProperty(chaseEvent, 'currentTarget', { value: parkElement }); |
| 165 | + Object.defineProperty(chaseEvent, 'wagging', { value: true, enumerable: false }); |
| 166 | + |
| 167 | + expect(normalize(chaseEvent)).toEqual({ |
| 168 | + currentTarget: 'park', |
| 169 | + isTrusted: false, |
| 170 | + target: 'park > tree > squirrel', |
| 171 | + type: 'chase', |
| 172 | + // notice that `wagging` isn't included because it's not enumerable and not one of the ones we specifically extract |
| 173 | + }); |
| 174 | + |
| 175 | + isElement.mockRestore(); |
144 | 176 | }); |
145 | 177 | }); |
146 | 178 |
|
|
0 commit comments