Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a footer and a couple tests - Snapshot Test Example #4

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Testing.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Testing

## TDD - Test Driven Development

## Types of Test

- Smoke Tests
- Does it exist
- Unit Tests
- Testing each item in isolation
- Snapshot Tests
- Freeze it / i like it today
- Visual / UI Snapshot
- Percy.IO
- etc
14 changes: 14 additions & 0 deletions __tests__/__snapshots__/header.test.tsx.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Header Looks Great 1`] = `
<DocumentFragment>
<nav>
Platform Starter
<a
href="/login"
>
Login
</a>
</nav>
</DocumentFragment>
`;
11 changes: 11 additions & 0 deletions __tests__/footer.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { render } from "@testing-library/react";
import Footer from "../src/components/Footer";

describe("Footer", () => {
it("Has correct year", () => {
// const MockFooter = () => <footer>2022</footer>;
const {getByText} = render(<Footer />)
// const { getByText } = render(<MockFooter />);
expect(getByText(2022)).toBeTruthy();
});
});
10 changes: 10 additions & 0 deletions __tests__/header.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { render } from "@testing-library/react";
import Header from "../src/components/Header";

describe("Header", () => {
it("Looks Great", () => {
const { asFragment } = render(<Header />);

expect(asFragment()).toMatchSnapshot();
});
});
14 changes: 11 additions & 3 deletions pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import '../styles/globals.css'
import type { AppProps } from 'next/app'
import "../styles/globals.css";
import type { AppProps } from "next/app";
import Footer from "../src/components/Footer";
import Header from "../src/components/Header";

export default function App({ Component, pageProps }: AppProps) {
return <Component {...pageProps} />
return (
<>
<Header />
<Component {...pageProps} />
<Footer />
</>
);
}
9 changes: 9 additions & 0 deletions src/components/Footer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from 'react'

function Footer() {
return (
<div>2022</div>
)
}

export default Footer
13 changes: 13 additions & 0 deletions src/components/Header.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import Link from "next/link";
import React from "react";

function Header() {
return (
<nav>
Platform Starter
<Link href="/login">Login</Link>
</nav>
);
}

export default Header;
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
"jsx": "preserve",
"incremental": true
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", "__tests__/firstTest.test.js"],
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", "__tests__/firstTest.test.jsx"],
"exclude": ["node_modules"]
}