diff --git a/packages/react-native/src/private/webapis/performance/__tests__/EventTimingAPI-itest.js b/packages/react-native/src/private/webapis/performance/__tests__/EventTimingAPI-itest.js index 4139eaaa29d..9f9e6615ccf 100644 --- a/packages/react-native/src/private/webapis/performance/__tests__/EventTimingAPI-itest.js +++ b/packages/react-native/src/private/webapis/performance/__tests__/EventTimingAPI-itest.js @@ -248,4 +248,65 @@ describe('Event Timing API', () => { expect([...performance.eventCounts.values()]).toEqual([1, 1, 3]); }); + + describe('durationThreshold option', () => { + it('works when used with `type`', () => { + const callback = jest.fn(); + + const observer = new PerformanceObserver(callback); + observer.observe({type: 'event', durationThreshold: 50}); + + let forceDelay = false; + + function MyComponent() { + const [count, setCount] = useState(0); + + return ( + { + if (forceDelay) { + sleep(50); + } + setCount(count + 1); + }}> + {count} + + ); + } + + const root = Fantom.createRoot(); + Fantom.runTask(() => { + root.render(); + }); + + const element = nullthrows( + root.document.documentElement.firstElementChild, + ); + + expect(callback).not.toHaveBeenCalled(); + + Fantom.dispatchNativeEvent(element, 'click'); + + expect(callback).toHaveBeenCalledTimes(0); + + forceDelay = true; + + Fantom.dispatchNativeEvent(element, 'click'); + + expect(callback).toHaveBeenCalledTimes(1); + }); + + it('throws when used together with `entryTypes`', () => { + const observer = new PerformanceObserver(() => {}); + + expect(() => { + observer.observe({ + entryTypes: ['event', 'mark'], + durationThreshold: 100, + }); + }).toThrow( + `Failed to execute 'observe' on 'PerformanceObserver': An observe() call must not include both entryTypes and durationThreshold arguments.`, + ); + }); + }); });