From bb15a9839b8d13910a4aa571fb3c399eced61646 Mon Sep 17 00:00:00 2001 From: Leonardo Zizzamia Date: Tue, 13 Aug 2024 14:48:30 -0700 Subject: [PATCH] tests --- .../components/Transaction.test.tsx | 37 ++++++++++++++++--- 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/src/transaction/components/Transaction.test.tsx b/src/transaction/components/Transaction.test.tsx index 9306283fac..9d4b48cbab 100644 --- a/src/transaction/components/Transaction.test.tsx +++ b/src/transaction/components/Transaction.test.tsx @@ -1,15 +1,20 @@ import { render, screen } from '@testing-library/react'; import { describe, expect, it, vi } from 'vitest'; import { Transaction } from './Transaction'; +import { TransactionProvider } from './TransactionProvider'; vi.mock('./TransactionProvider', () => ({ - TransactionProvider: ({ children }: { children: React.ReactNode }) => ( + TransactionProvider: vi.fn(({ children }: { children: React.ReactNode }) => (
{children}
- ), + )), })); describe('Transaction', () => { - it('renders the children inside the TransactionProvider', () => { + beforeEach(() => { + vi.clearAllMocks(); + }); + + it('should renders the children inside the TransactionProvider', () => { render( {
Test Child
, ); - expect(screen.getByText('Test Child')).toBeInTheDocument(); }); - it('applies the correct className', () => { + it('should applies the correct className', () => { render( {
Test Child
, ); - // Checking if the div has the correct classes applied const container = screen.getByText('Test Child').parentElement; expect(container).toHaveClass('test-class'); }); + + it('should call TransactionProvider', () => { + const onError = vi.fn(); + const onStatus = vi.fn(); + const onSuccess = vi.fn(); + render( + +
Test Child
+
, + ); + // Checking if the TransactionProvider is called + expect(TransactionProvider).toHaveBeenCalledTimes(1); + }); });