Skip to content
This repository has been archived by the owner on Oct 17, 2024. It is now read-only.

illustrate that api is not in coverage #26

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
5 changes: 5 additions & 0 deletions nextjs-coverage/src/components/App.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ test("smoke", async () => {
await expect(page).toHaveSelector("[data-testid=button]");
});

test("api got fetched", async () => {
jest.setTimeout(60000);
await expect(page).toHaveText("hello world");
});

test("click", async () => {
jest.setTimeout(60000);

Expand Down
7 changes: 7 additions & 0 deletions nextjs-coverage/src/pages/api/hello.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { NextApiRequest, NextApiResponse } from "next";

export default function (req: NextApiRequest, res: NextApiResponse) {
res.send({
text: `hello world`,
});
}
19 changes: 16 additions & 3 deletions nextjs-coverage/src/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
import Head from 'next/head'
import styles from '../styles/Home.module.css'
import App from '../components/App'
import Head from "next/head";
import styles from "../styles/Home.module.css";
import App from "../components/App";
import { useEffect, useState } from "react";

export default function Home() {
const [helloEndpointData, setHelloEndpointData] = useState<unknown>(null);
useEffect(() => {
// this is just for illustrative purposes, it's not a good way to handle fetching
async function fetchData() {
const json = (await fetch("/api/hello")).json();
return json;
}
fetchData().then(setHelloEndpointData);
}, []);

return (
<div className={styles.container}>
<Head>
Expand All @@ -25,6 +36,8 @@ export default function Home() {
</div>

<p>debug: NODE_ENV = {process.env.NODE_ENV}</p>

<p>api response: <code>{JSON.stringify(helloEndpointData, null, 4)}</code></p>
</main>

<footer className={styles.footer}>
Expand Down