ensure mocks are used wherever possible, more test fixes
All checks were successful
Deploy to Test Environment / deploy-to-test (push) Successful in 1h7m5s
All checks were successful
Deploy to Test Environment / deploy-to-test (push) Successful in 1h7m5s
This commit is contained in:
35
src/components/Footer.test.tsx
Normal file
35
src/components/Footer.test.tsx
Normal file
@@ -0,0 +1,35 @@
|
||||
// src/components/Footer.test.tsx
|
||||
import React from 'react';
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
||||
import { Footer } from './Footer';
|
||||
|
||||
describe('Footer', () => {
|
||||
beforeEach(() => {
|
||||
// Set up fake timers to control the date
|
||||
vi.useFakeTimers();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
// Restore real timers after each test
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
it('should render the copyright notice with the correct year', () => {
|
||||
// Arrange: Set a specific date for a predictable test outcome
|
||||
const mockDate = new Date('2025-08-22T10:00:00Z');
|
||||
vi.setSystemTime(mockDate);
|
||||
|
||||
// Act: Render the component
|
||||
render(<Footer />);
|
||||
|
||||
// Assert: Check that the rendered text includes the mocked year
|
||||
expect(screen.getByText('Copyright 2025-2025')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('should display the correct year when it changes', () => {
|
||||
vi.setSystemTime(new Date('2030-01-01T00:00:00Z'));
|
||||
render(<Footer />);
|
||||
expect(screen.getByText('Copyright 2025-2030')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
11
src/components/Footer.tsx
Normal file
11
src/components/Footer.tsx
Normal file
@@ -0,0 +1,11 @@
|
||||
// src/components/Footer.tsx
|
||||
import React from 'react';
|
||||
|
||||
export const Footer: React.FC = () => {
|
||||
const currentYear = new Date().getFullYear();
|
||||
return (
|
||||
<footer className="text-center text-xs text-gray-500 dark:text-gray-400 py-4">
|
||||
Copyright 2025-{currentYear}
|
||||
</footer>
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user