From 2a66e99946171ddb8c5f0f6ac5d40f3e31d3ca6c Mon Sep 17 00:00:00 2001 From: Nate Massey Date: Mon, 25 Mar 2024 10:42:27 -0700 Subject: [PATCH] fix: usePanGestureProxy.test: add a test to ensure the console.error was not called --- src/hooks/usePanGestureProxy.test.tsx | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/hooks/usePanGestureProxy.test.tsx b/src/hooks/usePanGestureProxy.test.tsx index 4bd649c2..4e22f95d 100644 --- a/src/hooks/usePanGestureProxy.test.tsx +++ b/src/hooks/usePanGestureProxy.test.tsx @@ -140,6 +140,29 @@ describe("Using RNGH v2 gesture API", () => { expect.objectContaining({ translationX: 20 }), ); }); + + it("does not include console.error in the output", () => { + // if react-native-gesture-handler detects that some handlers are + // workletized and some are not, it will log an error to the + // console. We'd like to make sure that this doesn't happen. + + // The error that would be shown looks like: + // [react-native-gesture-handler] Some of the callbacks in the gesture are worklets and some are not. Either make sure that all calbacks are marked as 'worklet' if you wish to run them on the UI thread or use '.runOnJS(true)' modifier on the gesture explicitly to run all callbacks on the JS thread. + + const panHandlers = mockedEventHandlers(); + const panHandlersFromUser = mockedEventHandlersFromUser(); + + jest.spyOn(console, "error"); + + render(); + fireGestureHandler(getByGestureTestId("pan"), [ + { state: State.BEGAN }, + { state: State.ACTIVE }, + { state: State.END }, + ]); + + expect(console.error).not.toBeCalled(); + }); }); describe("Event list validation", () => {