Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Zizzamia committed Aug 13, 2024
1 parent c38368d commit bb15a98
Showing 1 changed file with 31 additions and 6 deletions.
37 changes: 31 additions & 6 deletions src/transaction/components/Transaction.test.tsx
Original file line number Diff line number Diff line change
@@ -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 }) => (
<div>{children}</div>
),
)),
}));

describe('Transaction', () => {
it('renders the children inside the TransactionProvider', () => {
beforeEach(() => {
vi.clearAllMocks();
});

it('should renders the children inside the TransactionProvider', () => {
render(
<Transaction
address="0x123"
Expand All @@ -23,11 +28,10 @@ describe('Transaction', () => {
<div>Test Child</div>
</Transaction>,
);

expect(screen.getByText('Test Child')).toBeInTheDocument();
});

it('applies the correct className', () => {
it('should applies the correct className', () => {
render(
<Transaction
address="0x123"
Expand All @@ -41,9 +45,30 @@ describe('Transaction', () => {
<div>Test Child</div>
</Transaction>,
);

// 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(
<Transaction
address="0x123"
capabilities={{}}
chainId={123}
className="test-class"
contracts={[]}
onError={onError}
onStatus={onStatus}
onSuccess={onSuccess}
>
<div>Test Child</div>
</Transaction>,
);
// Checking if the TransactionProvider is called
expect(TransactionProvider).toHaveBeenCalledTimes(1);
});
});

0 comments on commit bb15a98

Please sign in to comment.