Skip to content

Commit a08244d

Browse files
committed
Add example test
1 parent ac6eb69 commit a08244d

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
describe('Navigation', () => {
2+
it('should navigate to the about page', () => {
3+
// Start from the index page
4+
cy.visit('http://localhost:3000/')
5+
6+
// Find a link with an href attribute containing "about" and click it
7+
cy.get('a[href*="about"]').click()
8+
9+
// The new url should include "/about"
10+
cy.url().should('include', '/about')
11+
12+
// The new page should contain an h1 with "About page"
13+
cy.get('h1').contains('About Page')
14+
})
15+
})
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import styles from '../styles/Home.module.css'
2+
import Link from 'next/link'
3+
4+
export default function About() {
5+
return (
6+
<div className={styles.container}>
7+
<main className={styles.main}>
8+
<h1>About Page</h1>
9+
<p className={styles.description}>
10+
<Link href="/">
11+
<a>&larr; Go Back</a>
12+
</Link>
13+
</p>
14+
</main>
15+
</div>
16+
)
17+
}

examples/with-cypress/pages/index.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Head from 'next/head'
22
import Image from 'next/image'
3+
import Link from 'next/link'
34
import styles from '../styles/Home.module.css'
45

56
export default function Home() {
@@ -22,6 +23,13 @@ export default function Home() {
2223
</p>
2324

2425
<div className={styles.grid}>
26+
<Link href="/about">
27+
<a className={styles.card}>
28+
<h2>About Page &rarr;</h2>
29+
<p>Cypress will test if this link is working.</p>
30+
</a>
31+
</Link>
32+
2533
<a href="https://nextjs.org/docs" className={styles.card}>
2634
<h2>Documentation &rarr;</h2>
2735
<p>Find in-depth information about Next.js features and API.</p>

0 commit comments

Comments
 (0)