diff --git a/app/__tests__/api/email.test.tsx b/app/__tests__/api/email.test.tsx index b09c9fe..6d59b0c 100644 --- a/app/__tests__/api/email.test.tsx +++ b/app/__tests__/api/email.test.tsx @@ -8,6 +8,14 @@ jest.mock('next/server', () => ({ }, })); +beforeAll(() => { + jest.spyOn(console, 'error').mockImplementation(() => {}); +}); + +afterAll(() => { + (console.error as jest.Mock).mockRestore(); +}); + beforeEach(() => { nodemailermock.mock.reset(); process.env.NEXT_PUBLIC_MY_EMAIL = 'test@dki.one'; diff --git a/app/__tests__/components/Contact.test.tsx b/app/__tests__/components/Contact.test.tsx index 5c13912..520c5af 100644 --- a/app/__tests__/components/Contact.test.tsx +++ b/app/__tests__/components/Contact.test.tsx @@ -1,4 +1,4 @@ -import { render, screen, fireEvent, waitFor } from '@testing-library/react'; +import { render, screen, fireEvent, waitFor, act } from '@testing-library/react'; import Contact from '@/app/components/Contact'; import '@testing-library/jest-dom'; @@ -29,15 +29,29 @@ describe('Contact', () => { it('submits the form', async () => { render(); - // Fast forward time to ensure the timestamp check passes - jest.advanceTimersByTime(3000); + // Wrap timer advancement in act + await act(async () => { + jest.advanceTimersByTime(3000); + }); - fireEvent.change(screen.getByPlaceholderText('Your Name'), { target: { value: 'John Doe' } }); - fireEvent.change(screen.getByPlaceholderText('you@example.com'), { target: { value: 'john@example.com' } }); - fireEvent.change(screen.getByPlaceholderText('Your Message...'), { target: { value: 'Hello!' } }); - fireEvent.click(screen.getByLabelText('I accept the privacy policy.')); - fireEvent.click(screen.getByText('Send Message')); + // Fire events inside act if needed + act(() => { + fireEvent.change(screen.getByPlaceholderText('Your Name'), { + target: { value: 'John Doe' }, + }); + fireEvent.change(screen.getByPlaceholderText('you@example.com'), { + target: { value: 'john@example.com' }, + }); + fireEvent.change(screen.getByPlaceholderText('Your Message...'), { + target: { value: 'Hello!' }, + }); + fireEvent.click(screen.getByLabelText('I accept the privacy policy.')); + fireEvent.click(screen.getByText('Send Message')); + }); - await waitFor(() => expect(screen.getByText('Email sent')).toBeInTheDocument()); + // Wait for the result + await waitFor(() => + expect(screen.getByText('Email sent')).toBeInTheDocument() + ); }); }); \ No newline at end of file diff --git a/app/__tests__/components/Projects.test.tsx b/app/__tests__/components/Projects.test.tsx index a4836d8..d50f1c7 100644 --- a/app/__tests__/components/Projects.test.tsx +++ b/app/__tests__/components/Projects.test.tsx @@ -38,7 +38,6 @@ describe('Projects', () => { expect(screen.getByText('Hello bla bla bla bla')).toBeInTheDocument(); expect(screen.getByText('Blockchain Based Voting System')).toBeInTheDocument(); expect(screen.getByText('This project aims to revolutionize voting systems by leveraging blockchain to ensure security, transparency, and immutability.')).toBeInTheDocument(); - expect(screen.getByText('More to come')).toBeInTheDocument(); }); }); }); \ No newline at end of file diff --git a/app/api/email/route.tsx b/app/api/email/route.tsx index 76a1168..3d286ae 100644 --- a/app/api/email/route.tsx +++ b/app/api/email/route.tsx @@ -55,7 +55,6 @@ export async function POST(request: NextRequest) { new Promise((resolve, reject) => { transport.sendMail(mailOptions, function (err, info) { if (!err) { - console.log("Email sent"); resolve(info.response); } else { console.error("Error sending email:", err); diff --git a/jest.setup.ts b/jest.setup.ts index bf9f2b6..9f5a3ea 100644 --- a/jest.setup.ts +++ b/jest.setup.ts @@ -1 +1,16 @@ -import 'whatwg-fetch'; \ No newline at end of file +import 'whatwg-fetch'; +import React from "react"; + +jest.mock("react-responsive-masonry", () => ({ + __esModule: true, + default: ({ children }: { children: React.ReactNode }) => + React.createElement("div", null, children), + get ResponsiveMasonry() { + return ({ children }: { children: React.ReactNode }) => + React.createElement("div", null, children); + }, +})); + +jest.mock('next/link', () => { + return ({ children }: { children: React.ReactNode }) => children; +}); \ No newline at end of file