The DailyNews frontend test suite uses Jest 29 with React Testing Library (RTL) and ts-jest to compile TypeScript on the fly. Tests run in aDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/miikorz/DailyNews/llms.txt
Use this file to discover all available pages before exploring further.
jsdom environment that simulates a browser DOM without a real browser. The five test files in src/test/ cover the main page components and the MultiTool UI primitive, asserting on rendered text, DOM roles, element attributes, navigation behaviour, and form validation. The useFeedManagement hook is mocked in every test that touches data-fetching, keeping tests fast and deterministic.
Test Structure
NewsHome.test.tsx — hero content and list mounting
NewsHome.test.tsx — hero content and list mounting
Tests that
NewsHome renders the welcome heading and the tagline paragraph, and that the <NewsList> component produces a list ARIA role. useFeedManagement is mocked to return an empty feed list so no real HTTP requests are made.Assertions covered:- “Welcome to your main feed of news” heading is in the document
- Tagline paragraph is in the document
- A
role="list"element is present
NewsList.test.tsx — feed card rendering and attributes
NewsList.test.tsx — feed card rendering and attributes
Mocks
useFeedManagement with two pre-built feed objects and asserts that titles, descriptions, authors, link href attributes, and image src attributes are correctly rendered.Assertions covered:- Both feed titles, descriptions, and authors appear in the DOM
- Each card
<a>element has the correcthreffromfeed.link - Each
<img>element has the correctsrcfromfeed.portrait
NewsDetail.test.tsx — form rendering, validation, and submission
NewsDetail.test.tsx — form rendering, validation, and submission
Mocks both
useFeedManagement and useParams (to return { id: '1' } so the form renders in edit mode). Also mocks the global fetch API with jest.fn().Assertions covered:- Title and Link labelled inputs are present
- Submitting an empty form shows “Title is required” and “Link is required” validation messages
- Submitting a form with valid
feedDatacallsupdateFeedwith the correct arguments - Toast notification mechanism is exercised via
ToastProvider
NotFound.test.tsx — 404 page content
NotFound.test.tsx — 404 page content
Renders
NotFound inside a BrowserRouter with a wildcard Route. Asserts that all three expected UI elements appear.Assertions covered:- “404” heading is in the document
- Error message paragraph is in the document
- “Go Home” link with
role="link"is in the document
MultiTool.test.tsx — floating action button behaviour
MultiTool.test.tsx — floating action button behaviour
Running Tests
Jest Configuration
The project uses a CommonJS Jest config file so it can be loaded without the ES module pipeline.| Setting | Value | Purpose |
|---|---|---|
preset | ts-jest | Compiles TypeScript files using ts-jest instead of Babel |
testEnvironment | jest-environment-jsdom | Provides a full DOM API (window, document, fetch stubs) inside Node.js |
transform | ts-jest for .ts/.tsx | Ensures TypeScript is compiled on every test run |
moduleNameMapper (CSS) | identity-obj-proxy | Returns the class name string for CSS Module imports so they don’t crash |
moduleNameMapper (assets) | fileMock.js | Returns a stub string for image and font imports |
setupFilesAfterEnv | setupTests.ts | Runs @testing-library/jest-dom matchers setup before each test suite |
Test Example
The following test fromNewsList.test.tsx demonstrates how useFeedManagement is mocked, how the component is wrapped in the required providers, and how RTL queries assert on rendered feed data:
Mocking
Mockingfetch
Tests that exercise code paths calling fetch (such as NewsDetail.test.tsx) replace the global with a Jest mock function in a beforeAll block:
fetch resolves to via (global.fetch as jest.Mock).mockResolvedValue(...).
Mocking static assets (fileMock.js)
Vite handles static asset imports natively, but Jest does not. The moduleNameMapper in jest.config.cjs redirects any import matching \.(gif|ttf|eot|svg|png)$ to src/test/__mocks__/fileMock.js, which exports a simple stub string so icon and image imports don’t throw during tests.
Mocking useFeedManagement
Because useFeedManagement calls useNavigate and useToast internally, mocking it at the module level (jest.mock('../customHooks/useFeedManagement')) prevents test files from needing a fully wired-up router and context just to render a component. Each beforeEach block calls mockReturnValue with a complete mock object that satisfies the hook’s return type.