Skip to content

Commit

Permalink
feat: add tests for page in App Router
Browse files Browse the repository at this point in the history
  • Loading branch information
ixartz committed Dec 4, 2023
1 parent bc7c386 commit 6a722a1
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/app/[locale]/about/page.test.tsx
@@ -0,0 +1,18 @@
import { render, screen } from '@testing-library/react';

import About from './page';

// The easiest solution to mock `next/router`: https://github.com/vercel/next.js/issues/7479
// The mock has been moved to `__mocks__` folder to avoid duplication

describe('About page', () => {
describe('Render method', () => {
it('should have two paragraphs of `Lorem ipsum`', () => {
render(<About />);

const paragraph = screen.getAllByText(/Lorem ipsum/);

expect(paragraph).toHaveLength(2);
});
});
});
20 changes: 20 additions & 0 deletions src/app/[locale]/page.test.tsx
@@ -0,0 +1,20 @@
import { render, screen } from '@testing-library/react';

import Index from './page';

// The easiest solution to mock `next/router`: https://github.com/vercel/next.js/issues/7479
// The mock has been moved to `__mocks__` folder to avoid duplication

describe('Index page', () => {
describe('Render method', () => {
it('should have h1 tag', () => {
render(<Index />);

const heading = screen.getByRole('heading', {
name: /Boilerplate code/,
});

expect(heading).toBeInTheDocument();
});
});
});

0 comments on commit 6a722a1

Please sign in to comment.