Add tests for durationThreshold option for PerformanceObserver (#52464)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/52464

Changelog: [internal]

This adds tests for the `durationThreshold` option for `PerformanceObserver.prototype.observe`.

Reviewed By: huntie

Differential Revision: D77860882

fbshipit-source-id: 1e56391166523d2c4f837f758bc367b58fe8e82e
This commit is contained in:
Rubén Norte
2025-07-07 06:42:23 -07:00
committed by Facebook GitHub Bot
parent e6bff3f1fe
commit 9f8179afa7
@@ -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 (
<View
onClick={event => {
if (forceDelay) {
sleep(50);
}
setCount(count + 1);
}}>
<Text>{count}</Text>
</View>
);
}
const root = Fantom.createRoot();
Fantom.runTask(() => {
root.render(<MyComponent />);
});
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.`,
);
});
});
});