From ad2ed7a13f6c0dbf4bf4766528fb3bdba2e75952 Mon Sep 17 00:00:00 2001
From: Jakub Szymczak <szymczak.jakub12@gmail.com>
Date: Wed, 25 Jun 2025 17:17:10 +0200
Subject: [PATCH 1/4] add useNewTransactions tests

---
 tests/unit/useNewTransactionsTest.ts | 294 +++++++++++++++++++++++++++
 1 file changed, 294 insertions(+)
 create mode 100644 tests/unit/useNewTransactionsTest.ts

diff --git a/tests/unit/useNewTransactionsTest.ts b/tests/unit/useNewTransactionsTest.ts
new file mode 100644
index 000000000000..fcc5b747c391
--- /dev/null
+++ b/tests/unit/useNewTransactionsTest.ts
@@ -0,0 +1,294 @@
+import {renderHook} from '@testing-library/react-native';
+import useNewTransactions from '@hooks/useNewTransactions';
+import type {Transaction} from '@src/types/onyx';
+
+// We need to mock requestAnimationFrame to mimic long Onyx merge overhead
+jest.spyOn(global, 'requestAnimationFrame').mockImplementation((callback: FrameRequestCallback) => {
+    setTimeout(() => {
+        callback(performance.now());
+    }, 30);
+    return 0;
+});
+
+// eslint-disable-next-line no-promise-executor-return
+const delay = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
+
+describe('useNewTransactions after clean cache', () => {
+    const transactionsAlreadyInReport = [
+        {transactionID: '2', amount: 200, created: '2023-10-02', currency: 'USD', reportID: 'report1', merchant: ''},
+        {transactionID: '3', amount: 300, created: '2023-10-03', currency: 'USD', reportID: 'report1', merchant: ''},
+    ];
+    const newTransaction = {transactionID: '1', amount: 100, created: '2023-10-01T00:00:00Z', currency: 'USD', reportID: 'report1', merchant: ''};
+
+    it("doesn't return new transactions when no transactions are added", async () => {
+        // 1. Report and transactions data is not loaded yet
+        const {rerender, result} = renderHook((props) => useNewTransactions(props.hasOnceLoadedReportActions, props.transactions), {
+            initialProps: {
+                hasOnceLoadedReportActions: false,
+                transactions: [],
+            },
+        });
+        await delay(10); // We need to wait to ensure that usePrevious hook updates correctly
+
+        // 2. Report is loaded and it has no transactions so there are no further rerenders
+        rerender({
+            hasOnceLoadedReportActions: true,
+            transactions: [],
+        });
+        expect(result.current).toEqual([]);
+    });
+
+    it('returns no new transactions when transactions come from initial Report load', async () => {
+        // 1. Report and transactions data is not loaded yet
+        const {rerender, result} = renderHook((props) => useNewTransactions(props.hasOnceLoadedReportActions, props.transactions), {
+            initialProps: {
+                hasOnceLoadedReportActions: false,
+                transactions: [] as Transaction[],
+            },
+        });
+        await delay(10); // We need to wait to ensure that usePrevious hook updates correctly
+        expect(result.current).toEqual([]);
+
+        // 2. Report is loaded and transactions data is not loaded yet
+        rerender({
+            hasOnceLoadedReportActions: true,
+            transactions: [],
+        });
+        await delay(10);
+        expect(result.current).toEqual([]);
+
+        // 3. Report is loaded and transactions data is loaded
+        rerender({
+            hasOnceLoadedReportActions: true,
+            transactions: transactionsAlreadyInReport,
+        });
+        expect(result.current).toEqual([]); // there is no new transactions, because the transactions that were already in the report are not considered new
+    });
+
+    it('returns new transactions when transactions are added after initial load', async () => {
+        // 1. Report and transactions data is not loaded yet
+        const {rerender, result} = renderHook((props) => useNewTransactions(props.hasOnceLoadedReportActions, props.transactions), {
+            initialProps: {
+                hasOnceLoadedReportActions: false,
+                transactions: [] as Transaction[],
+            },
+        });
+        await delay(10); // We need to wait to ensure that usePrevious hook updates correctly
+        expect(result.current).toEqual([]);
+
+        // 2. Report is loaded and transactions data is not loaded yet
+        rerender({
+            hasOnceLoadedReportActions: true,
+            transactions: [],
+        });
+        await delay(10);
+        expect(result.current).toEqual([]);
+
+        // 3. Report is loaded and transactions data is loaded
+        rerender({
+            hasOnceLoadedReportActions: true,
+            transactions: transactionsAlreadyInReport,
+        });
+        await delay(10);
+        expect(result.current).toEqual([]);
+
+        // 4. User added new transaction
+        rerender({
+            hasOnceLoadedReportActions: true,
+            transactions: [...transactionsAlreadyInReport, newTransaction],
+        });
+        expect(result.current).toEqual([newTransaction]);
+    });
+
+    it('returns new transactions when adding transactions to empty report', async () => {
+        // 1. Report and transactions data is not loaded yet
+        const {rerender, result} = renderHook((props) => useNewTransactions(props.hasOnceLoadedReportActions, props.transactions), {
+            initialProps: {
+                hasOnceLoadedReportActions: false,
+                transactions: [] as Transaction[],
+            },
+        });
+        await delay(10); // We need to wait to ensure that usePrevious hook updates correctly
+
+        // 2. Report is loaded and it has no transactions so there are no further rerenders
+        rerender({
+            hasOnceLoadedReportActions: true,
+            transactions: [],
+        });
+        await delay(1000);
+        expect(result.current).toEqual([]);
+
+        // 3. User added new transaction
+        rerender({
+            hasOnceLoadedReportActions: true,
+            transactions: [newTransaction],
+        });
+        expect(result.current).toEqual([newTransaction]);
+    });
+
+    it('returns no new transactions when transactions are removed', async () => {
+        // 1. Report and transactions data is not loaded yet
+        const {rerender, result} = renderHook((props) => useNewTransactions(props.hasOnceLoadedReportActions, props.transactions), {
+            initialProps: {
+                hasOnceLoadedReportActions: false,
+                transactions: [] as Transaction[],
+            },
+        });
+        await delay(10); // We need to wait to ensure that usePrevious hook updates correctly
+        expect(result.current).toEqual([]);
+
+        // 2. Report is loaded and transactions data is not loaded yet
+        rerender({
+            hasOnceLoadedReportActions: true,
+            transactions: [],
+        });
+        await delay(10);
+        expect(result.current).toEqual([]);
+
+        // 3. Report is loaded and transactions data is loaded
+        rerender({
+            hasOnceLoadedReportActions: true,
+            transactions: transactionsAlreadyInReport,
+        });
+        await delay(10);
+        expect(result.current).toEqual([]);
+
+        // 4. User removes a transaction
+        rerender({
+            hasOnceLoadedReportActions: true,
+            transactions: transactionsAlreadyInReport.slice(1), // Remove the first transaction
+        });
+        await delay(10);
+        expect(result.current).toEqual([]);
+    });
+});
+
+describe('useNewTransactions with hydrated cache', () => {
+    const transactionsAlreadyInReport = [
+        {transactionID: '2', amount: 200, created: '2023-10-02', currency: 'USD', reportID: 'report1', merchant: ''},
+        {transactionID: '3', amount: 300, created: '2023-10-03', currency: 'USD', reportID: 'report1', merchant: ''},
+    ];
+    const newTransaction = {transactionID: '1', amount: 100, created: '2023-10-01T00:00:00Z', currency: 'USD', reportID: 'report1', merchant: ''};
+
+    it("doesn't return new transactions when no transactions are added", async () => {
+        // 1. Report and transactions data is loaded from Onyx
+        const {rerender, result} = renderHook((props) => useNewTransactions(props.hasOnceLoadedReportActions, props.transactions), {
+            initialProps: {
+                hasOnceLoadedReportActions: true,
+                transactions: [],
+            },
+        });
+        await delay(10); // We need to wait to ensure that usePrevious hook updates correctly
+
+        // 2. Report is loaded and transactions data is loaded, but there were no new transactions
+        rerender({
+            hasOnceLoadedReportActions: true,
+            transactions: [],
+        });
+        expect(result.current).toEqual([]);
+    });
+
+    it('returns new transactions when newly added transactions come from initial Report load', async () => {
+        // 1. Report and transactions data is loaded from Onyx
+        const {rerender, result} = renderHook((props) => useNewTransactions(props.hasOnceLoadedReportActions, props.transactions), {
+            initialProps: {
+                hasOnceLoadedReportActions: true,
+                transactions: transactionsAlreadyInReport,
+            },
+        });
+        await delay(10); // We need to wait to ensure that usePrevious hook updates correctly
+        expect(result.current).toEqual([]);
+
+        // 2. New transaction comes in when report is loaded
+        rerender({
+            hasOnceLoadedReportActions: true,
+            transactions: [...transactionsAlreadyInReport, newTransaction],
+        });
+        expect(result.current).toEqual([newTransaction]);
+    });
+
+    it('returns new transactions when transactions are added after initial load', async () => {
+        // 1. Report and transactions data is loaded from Onyx
+        const {rerender, result} = renderHook((props) => useNewTransactions(props.hasOnceLoadedReportActions, props.transactions), {
+            initialProps: {
+                hasOnceLoadedReportActions: true,
+                transactions: transactionsAlreadyInReport,
+            },
+        });
+        await delay(10); // We need to wait to ensure that usePrevious hook updates correctly
+        expect(result.current).toEqual([]);
+
+        // 2. Report is loaded and transactions data is loaded, but there were no new transactions
+        rerender({
+            hasOnceLoadedReportActions: true,
+            transactions: transactionsAlreadyInReport,
+        });
+        await delay(10);
+        expect(result.current).toEqual([]);
+
+        // 3. User added new transaction
+        rerender({
+            hasOnceLoadedReportActions: true,
+            transactions: [...transactionsAlreadyInReport, newTransaction],
+        });
+        expect(result.current).toEqual([newTransaction]);
+    });
+
+    it('returns new transactions when adding transactions to empty report', async () => {
+        // 1. Report and transactions data is loaded from Onyx
+        const {rerender, result} = renderHook((props) => useNewTransactions(props.hasOnceLoadedReportActions, props.transactions), {
+            initialProps: {
+                hasOnceLoadedReportActions: true,
+                transactions: [] as Transaction[],
+            },
+        });
+        await delay(10); // We need to wait to ensure that usePrevious hook updates correctly
+
+        // 2. Report is loaded and it has no transactions, so there are no further rerenders
+        rerender({
+            hasOnceLoadedReportActions: true,
+            transactions: [],
+        });
+        await delay(1000);
+        expect(result.current).toEqual([]);
+
+        // 3. User added new transaction
+        rerender({
+            hasOnceLoadedReportActions: true,
+            transactions: [newTransaction],
+        });
+        expect(result.current).toEqual([newTransaction]);
+    });
+
+    it('returns no new transactions when transactions are removed', async () => {
+        // 1. Report and transactions data is loaded from Onyx
+        const {rerender, result} = renderHook((props) => useNewTransactions(props.hasOnceLoadedReportActions, props.transactions), {
+            initialProps: {
+                hasOnceLoadedReportActions: true,
+                transactions: transactionsAlreadyInReport,
+            },
+        });
+        await delay(10); // We need to wait to ensure that usePrevious hook updates correctly
+        expect(result.current).toEqual([]);
+
+        // 2. Report is loaded and transactions data is loaded, but there were no new transactions
+        rerender({
+            hasOnceLoadedReportActions: true,
+            transactions: transactionsAlreadyInReport,
+        });
+        await delay(10);
+        expect(result.current).toEqual([]);
+
+        // 3. User removes a transaction
+        rerender({
+            hasOnceLoadedReportActions: true,
+            transactions: transactionsAlreadyInReport.slice(1), // Remove the first transaction
+        });
+        await delay(10);
+        expect(result.current).toEqual([]);
+    });
+});
+
+afterAll(() => {
+    jest.restoreAllMocks();
+});

From b89a2d688257feddd1cfcbd5a03a410f5b04b8a8 Mon Sep 17 00:00:00 2001
From: Jakub Szymczak <szymczak.jakub12@gmail.com>
Date: Thu, 26 Jun 2025 09:58:23 +0200
Subject: [PATCH 2/4] add explanatory comments

---
 tests/unit/useNewTransactionsTest.ts | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/tests/unit/useNewTransactionsTest.ts b/tests/unit/useNewTransactionsTest.ts
index fcc5b747c391..bc606620e879 100644
--- a/tests/unit/useNewTransactionsTest.ts
+++ b/tests/unit/useNewTransactionsTest.ts
@@ -13,7 +13,7 @@ jest.spyOn(global, 'requestAnimationFrame').mockImplementation((callback: FrameR
 // eslint-disable-next-line no-promise-executor-return
 const delay = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
 
-describe('useNewTransactions after clean cache', () => {
+describe('useNewTransactions after cleared cache', () => {
     const transactionsAlreadyInReport = [
         {transactionID: '2', amount: 200, created: '2023-10-02', currency: 'USD', reportID: 'report1', merchant: ''},
         {transactionID: '3', amount: 300, created: '2023-10-03', currency: 'USD', reportID: 'report1', merchant: ''},
@@ -115,7 +115,7 @@ describe('useNewTransactions after clean cache', () => {
             hasOnceLoadedReportActions: true,
             transactions: [],
         });
-        await delay(1000);
+        await delay(1000); // We need to wait to ensure that the second useEffect is executed
         expect(result.current).toEqual([]);
 
         // 3. User added new transaction
@@ -156,14 +156,14 @@ describe('useNewTransactions after clean cache', () => {
         // 4. User removes a transaction
         rerender({
             hasOnceLoadedReportActions: true,
-            transactions: transactionsAlreadyInReport.slice(1), // Remove the first transaction
+            transactions: transactionsAlreadyInReport.slice(1),
         });
         await delay(10);
         expect(result.current).toEqual([]);
     });
 });
 
-describe('useNewTransactions with hydrated cache', () => {
+describe('useNewTransactions with transactions in cache', () => {
     const transactionsAlreadyInReport = [
         {transactionID: '2', amount: 200, created: '2023-10-02', currency: 'USD', reportID: 'report1', merchant: ''},
         {transactionID: '3', amount: 300, created: '2023-10-03', currency: 'USD', reportID: 'report1', merchant: ''},

From 83c9754e141d76e36419c7e872b565a7c81a0f9e Mon Sep 17 00:00:00 2001
From: Jakub Szymczak <szymczak.jakub12@gmail.com>
Date: Fri, 27 Jun 2025 16:56:30 +0200
Subject: [PATCH 3/4] fix PR comments

---
 tests/unit/useNewTransactionsTest.ts | 106 ++++++++++++++++-----------
 1 file changed, 65 insertions(+), 41 deletions(-)

diff --git a/tests/unit/useNewTransactionsTest.ts b/tests/unit/useNewTransactionsTest.ts
index bc606620e879..095b8b88f6a0 100644
--- a/tests/unit/useNewTransactionsTest.ts
+++ b/tests/unit/useNewTransactionsTest.ts
@@ -10,10 +10,12 @@ jest.spyOn(global, 'requestAnimationFrame').mockImplementation((callback: FrameR
     return 0;
 });
 
-// eslint-disable-next-line no-promise-executor-return
-const delay = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
+const delay = (ms: number) =>
+    new Promise((resolve) => {
+        setTimeout(resolve, ms);
+    });
 
-describe('useNewTransactions after cleared cache', () => {
+describe('useNewTransactions with empty cache', () => {
     const transactionsAlreadyInReport = [
         {transactionID: '2', amount: 200, created: '2023-10-02', currency: 'USD', reportID: 'report1', merchant: ''},
         {transactionID: '3', amount: 300, created: '2023-10-03', currency: 'USD', reportID: 'report1', merchant: ''},
@@ -22,12 +24,15 @@ describe('useNewTransactions after cleared cache', () => {
 
     it("doesn't return new transactions when no transactions are added", async () => {
         // 1. Report and transactions data is not loaded yet
-        const {rerender, result} = renderHook((props) => useNewTransactions(props.hasOnceLoadedReportActions, props.transactions), {
-            initialProps: {
-                hasOnceLoadedReportActions: false,
-                transactions: [],
+        const {rerender, result} = renderHook<Transaction[], {transactions: Transaction[]; hasOnceLoadedReportActions: boolean}>(
+            (props) => useNewTransactions(props.hasOnceLoadedReportActions, props.transactions),
+            {
+                initialProps: {
+                    hasOnceLoadedReportActions: false,
+                    transactions: [],
+                },
             },
-        });
+        );
         await delay(10); // We need to wait to ensure that usePrevious hook updates correctly
 
         // 2. Report is loaded and it has no transactions so there are no further rerenders
@@ -40,12 +45,15 @@ describe('useNewTransactions after cleared cache', () => {
 
     it('returns no new transactions when transactions come from initial Report load', async () => {
         // 1. Report and transactions data is not loaded yet
-        const {rerender, result} = renderHook((props) => useNewTransactions(props.hasOnceLoadedReportActions, props.transactions), {
-            initialProps: {
-                hasOnceLoadedReportActions: false,
-                transactions: [] as Transaction[],
+        const {rerender, result} = renderHook<Transaction[], {transactions: Transaction[]; hasOnceLoadedReportActions: boolean}>(
+            (props) => useNewTransactions(props.hasOnceLoadedReportActions, props.transactions),
+            {
+                initialProps: {
+                    hasOnceLoadedReportActions: false,
+                    transactions: [],
+                },
             },
-        });
+        );
         await delay(10); // We need to wait to ensure that usePrevious hook updates correctly
         expect(result.current).toEqual([]);
 
@@ -62,17 +70,21 @@ describe('useNewTransactions after cleared cache', () => {
             hasOnceLoadedReportActions: true,
             transactions: transactionsAlreadyInReport,
         });
-        expect(result.current).toEqual([]); // there is no new transactions, because the transactions that were already in the report are not considered new
+        // there is no new transactions, because the transactions that were already in the report are not considered new
+        expect(result.current).toEqual([]);
     });
 
     it('returns new transactions when transactions are added after initial load', async () => {
         // 1. Report and transactions data is not loaded yet
-        const {rerender, result} = renderHook((props) => useNewTransactions(props.hasOnceLoadedReportActions, props.transactions), {
-            initialProps: {
-                hasOnceLoadedReportActions: false,
-                transactions: [] as Transaction[],
+        const {rerender, result} = renderHook<Transaction[], {transactions: Transaction[]; hasOnceLoadedReportActions: boolean}>(
+            (props) => useNewTransactions(props.hasOnceLoadedReportActions, props.transactions),
+            {
+                initialProps: {
+                    hasOnceLoadedReportActions: false,
+                    transactions: [],
+                },
             },
-        });
+        );
         await delay(10); // We need to wait to ensure that usePrevious hook updates correctly
         expect(result.current).toEqual([]);
 
@@ -102,12 +114,15 @@ describe('useNewTransactions after cleared cache', () => {
 
     it('returns new transactions when adding transactions to empty report', async () => {
         // 1. Report and transactions data is not loaded yet
-        const {rerender, result} = renderHook((props) => useNewTransactions(props.hasOnceLoadedReportActions, props.transactions), {
-            initialProps: {
-                hasOnceLoadedReportActions: false,
-                transactions: [] as Transaction[],
+        const {rerender, result} = renderHook<Transaction[], {transactions: Transaction[]; hasOnceLoadedReportActions: boolean}>(
+            (props) => useNewTransactions(props.hasOnceLoadedReportActions, props.transactions),
+            {
+                initialProps: {
+                    hasOnceLoadedReportActions: false,
+                    transactions: [],
+                },
             },
-        });
+        );
         await delay(10); // We need to wait to ensure that usePrevious hook updates correctly
 
         // 2. Report is loaded and it has no transactions so there are no further rerenders
@@ -115,7 +130,7 @@ describe('useNewTransactions after cleared cache', () => {
             hasOnceLoadedReportActions: true,
             transactions: [],
         });
-        await delay(1000); // We need to wait to ensure that the second useEffect is executed
+        await delay(1000); // We need to wait to ensure that the skipFirstTransactionsChange is set to false by the useEffect
         expect(result.current).toEqual([]);
 
         // 3. User added new transaction
@@ -128,12 +143,15 @@ describe('useNewTransactions after cleared cache', () => {
 
     it('returns no new transactions when transactions are removed', async () => {
         // 1. Report and transactions data is not loaded yet
-        const {rerender, result} = renderHook((props) => useNewTransactions(props.hasOnceLoadedReportActions, props.transactions), {
-            initialProps: {
-                hasOnceLoadedReportActions: false,
-                transactions: [] as Transaction[],
+        const {rerender, result} = renderHook<Transaction[], {transactions: Transaction[]; hasOnceLoadedReportActions: boolean}>(
+            (props) => useNewTransactions(props.hasOnceLoadedReportActions, props.transactions),
+            {
+                initialProps: {
+                    hasOnceLoadedReportActions: false,
+                    transactions: [],
+                },
             },
-        });
+        );
         await delay(10); // We need to wait to ensure that usePrevious hook updates correctly
         expect(result.current).toEqual([]);
 
@@ -172,12 +190,15 @@ describe('useNewTransactions with transactions in cache', () => {
 
     it("doesn't return new transactions when no transactions are added", async () => {
         // 1. Report and transactions data is loaded from Onyx
-        const {rerender, result} = renderHook((props) => useNewTransactions(props.hasOnceLoadedReportActions, props.transactions), {
-            initialProps: {
-                hasOnceLoadedReportActions: true,
-                transactions: [],
+        const {rerender, result} = renderHook<Transaction[], {transactions: Transaction[]; hasOnceLoadedReportActions: boolean}>(
+            (props) => useNewTransactions(props.hasOnceLoadedReportActions, props.transactions),
+            {
+                initialProps: {
+                    hasOnceLoadedReportActions: true,
+                    transactions: [],
+                },
             },
-        });
+        );
         await delay(10); // We need to wait to ensure that usePrevious hook updates correctly
 
         // 2. Report is loaded and transactions data is loaded, but there were no new transactions
@@ -236,12 +257,15 @@ describe('useNewTransactions with transactions in cache', () => {
 
     it('returns new transactions when adding transactions to empty report', async () => {
         // 1. Report and transactions data is loaded from Onyx
-        const {rerender, result} = renderHook((props) => useNewTransactions(props.hasOnceLoadedReportActions, props.transactions), {
-            initialProps: {
-                hasOnceLoadedReportActions: true,
-                transactions: [] as Transaction[],
+        const {rerender, result} = renderHook<Transaction[], {transactions: Transaction[]; hasOnceLoadedReportActions: boolean}>(
+            (props) => useNewTransactions(props.hasOnceLoadedReportActions, props.transactions),
+            {
+                initialProps: {
+                    hasOnceLoadedReportActions: true,
+                    transactions: [],
+                },
             },
-        });
+        );
         await delay(10); // We need to wait to ensure that usePrevious hook updates correctly
 
         // 2. Report is loaded and it has no transactions, so there are no further rerenders
@@ -282,7 +306,7 @@ describe('useNewTransactions with transactions in cache', () => {
         // 3. User removes a transaction
         rerender({
             hasOnceLoadedReportActions: true,
-            transactions: transactionsAlreadyInReport.slice(1), // Remove the first transaction
+            transactions: transactionsAlreadyInReport.slice(1),
         });
         await delay(10);
         expect(result.current).toEqual([]);

From 8ab5e1a8608ed553be16a0aedc7356a39412b0d8 Mon Sep 17 00:00:00 2001
From: Jakub Szymczak <szymczak.jakub12@gmail.com>
Date: Mon, 30 Jun 2025 11:06:17 +0200
Subject: [PATCH 4/4] delete redundant delays

---
 tests/unit/useNewTransactionsTest.ts | 35 +++++++---------------------
 1 file changed, 8 insertions(+), 27 deletions(-)

diff --git a/tests/unit/useNewTransactionsTest.ts b/tests/unit/useNewTransactionsTest.ts
index 095b8b88f6a0..fe8ca1290813 100644
--- a/tests/unit/useNewTransactionsTest.ts
+++ b/tests/unit/useNewTransactionsTest.ts
@@ -22,7 +22,7 @@ describe('useNewTransactions with empty cache', () => {
     ];
     const newTransaction = {transactionID: '1', amount: 100, created: '2023-10-01T00:00:00Z', currency: 'USD', reportID: 'report1', merchant: ''};
 
-    it("doesn't return new transactions when no transactions are added", async () => {
+    it("doesn't return new transactions when no transactions are added", () => {
         // 1. Report and transactions data is not loaded yet
         const {rerender, result} = renderHook<Transaction[], {transactions: Transaction[]; hasOnceLoadedReportActions: boolean}>(
             (props) => useNewTransactions(props.hasOnceLoadedReportActions, props.transactions),
@@ -33,7 +33,6 @@ describe('useNewTransactions with empty cache', () => {
                 },
             },
         );
-        await delay(10); // We need to wait to ensure that usePrevious hook updates correctly
 
         // 2. Report is loaded and it has no transactions so there are no further rerenders
         rerender({
@@ -43,7 +42,7 @@ describe('useNewTransactions with empty cache', () => {
         expect(result.current).toEqual([]);
     });
 
-    it('returns no new transactions when transactions come from initial Report load', async () => {
+    it('returns no new transactions when transactions come from initial Report load', () => {
         // 1. Report and transactions data is not loaded yet
         const {rerender, result} = renderHook<Transaction[], {transactions: Transaction[]; hasOnceLoadedReportActions: boolean}>(
             (props) => useNewTransactions(props.hasOnceLoadedReportActions, props.transactions),
@@ -54,7 +53,6 @@ describe('useNewTransactions with empty cache', () => {
                 },
             },
         );
-        await delay(10); // We need to wait to ensure that usePrevious hook updates correctly
         expect(result.current).toEqual([]);
 
         // 2. Report is loaded and transactions data is not loaded yet
@@ -62,7 +60,6 @@ describe('useNewTransactions with empty cache', () => {
             hasOnceLoadedReportActions: true,
             transactions: [],
         });
-        await delay(10);
         expect(result.current).toEqual([]);
 
         // 3. Report is loaded and transactions data is loaded
@@ -74,7 +71,7 @@ describe('useNewTransactions with empty cache', () => {
         expect(result.current).toEqual([]);
     });
 
-    it('returns new transactions when transactions are added after initial load', async () => {
+    it('returns new transactions when transactions are added after initial load', () => {
         // 1. Report and transactions data is not loaded yet
         const {rerender, result} = renderHook<Transaction[], {transactions: Transaction[]; hasOnceLoadedReportActions: boolean}>(
             (props) => useNewTransactions(props.hasOnceLoadedReportActions, props.transactions),
@@ -85,7 +82,6 @@ describe('useNewTransactions with empty cache', () => {
                 },
             },
         );
-        await delay(10); // We need to wait to ensure that usePrevious hook updates correctly
         expect(result.current).toEqual([]);
 
         // 2. Report is loaded and transactions data is not loaded yet
@@ -93,7 +89,6 @@ describe('useNewTransactions with empty cache', () => {
             hasOnceLoadedReportActions: true,
             transactions: [],
         });
-        await delay(10);
         expect(result.current).toEqual([]);
 
         // 3. Report is loaded and transactions data is loaded
@@ -101,7 +96,6 @@ describe('useNewTransactions with empty cache', () => {
             hasOnceLoadedReportActions: true,
             transactions: transactionsAlreadyInReport,
         });
-        await delay(10);
         expect(result.current).toEqual([]);
 
         // 4. User added new transaction
@@ -123,7 +117,6 @@ describe('useNewTransactions with empty cache', () => {
                 },
             },
         );
-        await delay(10); // We need to wait to ensure that usePrevious hook updates correctly
 
         // 2. Report is loaded and it has no transactions so there are no further rerenders
         rerender({
@@ -141,7 +134,7 @@ describe('useNewTransactions with empty cache', () => {
         expect(result.current).toEqual([newTransaction]);
     });
 
-    it('returns no new transactions when transactions are removed', async () => {
+    it('returns no new transactions when transactions are removed', () => {
         // 1. Report and transactions data is not loaded yet
         const {rerender, result} = renderHook<Transaction[], {transactions: Transaction[]; hasOnceLoadedReportActions: boolean}>(
             (props) => useNewTransactions(props.hasOnceLoadedReportActions, props.transactions),
@@ -152,7 +145,6 @@ describe('useNewTransactions with empty cache', () => {
                 },
             },
         );
-        await delay(10); // We need to wait to ensure that usePrevious hook updates correctly
         expect(result.current).toEqual([]);
 
         // 2. Report is loaded and transactions data is not loaded yet
@@ -160,7 +152,6 @@ describe('useNewTransactions with empty cache', () => {
             hasOnceLoadedReportActions: true,
             transactions: [],
         });
-        await delay(10);
         expect(result.current).toEqual([]);
 
         // 3. Report is loaded and transactions data is loaded
@@ -168,7 +159,6 @@ describe('useNewTransactions with empty cache', () => {
             hasOnceLoadedReportActions: true,
             transactions: transactionsAlreadyInReport,
         });
-        await delay(10);
         expect(result.current).toEqual([]);
 
         // 4. User removes a transaction
@@ -176,7 +166,6 @@ describe('useNewTransactions with empty cache', () => {
             hasOnceLoadedReportActions: true,
             transactions: transactionsAlreadyInReport.slice(1),
         });
-        await delay(10);
         expect(result.current).toEqual([]);
     });
 });
@@ -188,7 +177,7 @@ describe('useNewTransactions with transactions in cache', () => {
     ];
     const newTransaction = {transactionID: '1', amount: 100, created: '2023-10-01T00:00:00Z', currency: 'USD', reportID: 'report1', merchant: ''};
 
-    it("doesn't return new transactions when no transactions are added", async () => {
+    it("doesn't return new transactions when no transactions are added", () => {
         // 1. Report and transactions data is loaded from Onyx
         const {rerender, result} = renderHook<Transaction[], {transactions: Transaction[]; hasOnceLoadedReportActions: boolean}>(
             (props) => useNewTransactions(props.hasOnceLoadedReportActions, props.transactions),
@@ -199,7 +188,6 @@ describe('useNewTransactions with transactions in cache', () => {
                 },
             },
         );
-        await delay(10); // We need to wait to ensure that usePrevious hook updates correctly
 
         // 2. Report is loaded and transactions data is loaded, but there were no new transactions
         rerender({
@@ -209,7 +197,7 @@ describe('useNewTransactions with transactions in cache', () => {
         expect(result.current).toEqual([]);
     });
 
-    it('returns new transactions when newly added transactions come from initial Report load', async () => {
+    it('returns new transactions when newly added transactions come from initial Report load', () => {
         // 1. Report and transactions data is loaded from Onyx
         const {rerender, result} = renderHook((props) => useNewTransactions(props.hasOnceLoadedReportActions, props.transactions), {
             initialProps: {
@@ -217,7 +205,6 @@ describe('useNewTransactions with transactions in cache', () => {
                 transactions: transactionsAlreadyInReport,
             },
         });
-        await delay(10); // We need to wait to ensure that usePrevious hook updates correctly
         expect(result.current).toEqual([]);
 
         // 2. New transaction comes in when report is loaded
@@ -228,7 +215,7 @@ describe('useNewTransactions with transactions in cache', () => {
         expect(result.current).toEqual([newTransaction]);
     });
 
-    it('returns new transactions when transactions are added after initial load', async () => {
+    it('returns new transactions when transactions are added after initial load', () => {
         // 1. Report and transactions data is loaded from Onyx
         const {rerender, result} = renderHook((props) => useNewTransactions(props.hasOnceLoadedReportActions, props.transactions), {
             initialProps: {
@@ -236,7 +223,6 @@ describe('useNewTransactions with transactions in cache', () => {
                 transactions: transactionsAlreadyInReport,
             },
         });
-        await delay(10); // We need to wait to ensure that usePrevious hook updates correctly
         expect(result.current).toEqual([]);
 
         // 2. Report is loaded and transactions data is loaded, but there were no new transactions
@@ -244,7 +230,6 @@ describe('useNewTransactions with transactions in cache', () => {
             hasOnceLoadedReportActions: true,
             transactions: transactionsAlreadyInReport,
         });
-        await delay(10);
         expect(result.current).toEqual([]);
 
         // 3. User added new transaction
@@ -266,7 +251,6 @@ describe('useNewTransactions with transactions in cache', () => {
                 },
             },
         );
-        await delay(10); // We need to wait to ensure that usePrevious hook updates correctly
 
         // 2. Report is loaded and it has no transactions, so there are no further rerenders
         rerender({
@@ -284,7 +268,7 @@ describe('useNewTransactions with transactions in cache', () => {
         expect(result.current).toEqual([newTransaction]);
     });
 
-    it('returns no new transactions when transactions are removed', async () => {
+    it('returns no new transactions when transactions are removed', () => {
         // 1. Report and transactions data is loaded from Onyx
         const {rerender, result} = renderHook((props) => useNewTransactions(props.hasOnceLoadedReportActions, props.transactions), {
             initialProps: {
@@ -292,7 +276,6 @@ describe('useNewTransactions with transactions in cache', () => {
                 transactions: transactionsAlreadyInReport,
             },
         });
-        await delay(10); // We need to wait to ensure that usePrevious hook updates correctly
         expect(result.current).toEqual([]);
 
         // 2. Report is loaded and transactions data is loaded, but there were no new transactions
@@ -300,7 +283,6 @@ describe('useNewTransactions with transactions in cache', () => {
             hasOnceLoadedReportActions: true,
             transactions: transactionsAlreadyInReport,
         });
-        await delay(10);
         expect(result.current).toEqual([]);
 
         // 3. User removes a transaction
@@ -308,7 +290,6 @@ describe('useNewTransactions with transactions in cache', () => {
             hasOnceLoadedReportActions: true,
             transactions: transactionsAlreadyInReport.slice(1),
         });
-        await delay(10);
         expect(result.current).toEqual([]);
     });
 });
