File tree Expand file tree Collapse file tree 4 files changed +35
-5
lines changed Expand file tree Collapse file tree 4 files changed +35
-5
lines changed Original file line number Diff line number Diff line change 55 SEMANTIC_ATTRIBUTE_SENTRY_OP ,
66 SEMANTIC_ATTRIBUTE_URL_FULL ,
77 defineIntegration ,
8+ hasProp ,
89 spanToJSON ,
910} from '@sentry/core' ;
1011import type { Client , IntegrationFn } from '@sentry/core' ;
@@ -136,11 +137,6 @@ export function getRequestPayloadXhrOrFetch(hint: XhrHint | FetchHint): string |
136137 return body ;
137138}
138139
139- // Duplicate from deprecated @sentry -utils/src/instrument/fetch.ts
140- function hasProp < T extends string > ( obj : unknown , prop : T ) : obj is Record < string , string > {
141- return ! ! obj && typeof obj === 'object' && ! ! ( obj as Record < string , string > ) [ prop ] ;
142- }
143-
144140/**
145141 * Parses the fetch arguments to extract the request payload.
146142 * Exported for tests only.
Original file line number Diff line number Diff line change @@ -96,6 +96,7 @@ export {
9696 extractQueryParamsFromUrl ,
9797 headersToDict ,
9898} from './utils/request' ;
99+ export { hasProp } from './utils/hasProp' ;
99100export { DEFAULT_ENVIRONMENT } from './constants' ;
100101export { addBreadcrumb } from './breadcrumbs' ;
101102export { functionToStringIntegration } from './integrations/functiontostring' ;
Original file line number Diff line number Diff line change 1+ /**
2+ * A more comprehensive key property check.
3+ */
4+ export function hasProp < T extends string > ( obj : unknown , prop : T ) : obj is Record < string , unknown > {
5+ return ! ! obj && typeof obj === 'object' && ! ! ( obj as Record < string , unknown > ) [ prop ] ;
6+ }
Original file line number Diff line number Diff line change 1+ import { hasProp } from '../../../src/utils/hasProp' ;
2+
3+ describe ( 'hasProp' , ( ) => {
4+ it ( 'should return true if the object has the provided property' , ( ) => {
5+ const obj = { a : 1 } ;
6+ const result = hasProp ( obj , 'a' ) ;
7+ expect ( result ) . toBe ( true ) ;
8+ } ) ;
9+
10+ it ( 'should return false if the object does not have the provided property' , ( ) => {
11+ const obj = { a : 1 } ;
12+ const result = hasProp ( obj , 'b' ) ;
13+ expect ( result ) . toBe ( false ) ;
14+ } ) ;
15+
16+ it ( 'should return false if the object is null' , ( ) => {
17+ const obj = null ;
18+ const result = hasProp ( obj , 'a' ) ;
19+ expect ( result ) . toBe ( false ) ;
20+ } ) ;
21+
22+ it ( 'should return false if the object is undefined' , ( ) => {
23+ const obj = undefined ;
24+ const result = hasProp ( obj , 'a' ) ;
25+ expect ( result ) . toBe ( false ) ;
26+ } ) ;
27+ } ) ;
You can’t perform that action at this time.
0 commit comments