Pie Logo
Quiz: Testing Approaches
by Tomas Trescak

QuizTest your understanding of the section content.

ContentDetailed description of the section content.

Full Stack Development
Introduction
Generative AI
🍰 Player
💼 Editor
Setup
React Fundamentals
Next.js
Advanced React
Databases
React Hooks
Authentication and Authorisation
APIs
CI/CD and DevOps
Testing React
Introduction to Testing
Quiz: Testing Approaches
Component Testing with React Testing Library
Spying and Mocking
Component Testing with Playwright
End to End testing with Playwright
Exercise: Testing
Advanced Topics
    Pie Logo
    Quiz: Testing Approaches
    by Tomas Trescak

    QuizTest your understanding of the section content.

    ContentDetailed description of the section content.

    Full Stack Development
    Introduction
    Generative AI
    🍰 Player
    💼 Editor
    Setup
    React Fundamentals
    Next.js
    Advanced React
    Databases
    React Hooks
    Authentication and Authorisation
    APIs
    CI/CD and DevOps
    Testing React
    Introduction to Testing
    Quiz: Testing Approaches
    Component Testing with React Testing Library
    Spying and Mocking
    Component Testing with Playwright
    End to End testing with Playwright
    Exercise: Testing
    Advanced Topics
    QUESTION 1

    You’re debugging a test for the formatDate function in the blogging app. The test fails because it’s trying to fetch data from an API to create a Date object. Based on the lecture, what’s wrong with this test?


    QUESTION 2

    Here’s a test for the PostPreview component:

    import { render, screen } from "@testing-library/react";
    import { describe, it, expect } from "vitest";
    import { PostPreview } from "../components/PostPreview";
    describe("PostPreview", () => {
      it("renders correctly", () => {
        render(<PostPreview title="Test Post" date={new Date("2025-04-07")} />);
        expect(screen.getByText("Test Post")).toBeDefined();
        expect(screen.getByText("April 7, 2025")).toBeDefined();
      });
    });
    

    What type of test is this, and why?


    QUESTION 3

    Your team writes this test for the PostList component:

    import { render, screen } from "@testing-library/react";
    import { describe, it, expect, vi } from "vitest";
    import { PostList } from "../components/PostList";
    describe("PostList", () => {
      it("displays fetched posts", async () => {
        vi.spyOn(global, "fetch").mockResolvedValue({
          json: () => Promise.resolve([{ title: "Demo", date: "2025-04-07" }]),
        } as any);
        render(<PostList />);
        expect(await screen.findByText("Demo")).toBeDefined();
      });
    });
    

    A bug causes the PostPreview component to render the wrong date format. Will this test catch it?


    QUESTION 4

    You’re reviewing an E2E test written with Playwright:

    import { test, expect } from "@playwright/test";
    test("user adds a post", async ({ page }) => {
      await page.goto("http://localhost:3000/admin");
      await page.fill("#title", "New Post");
      await page.fill("#date", "2025-04-08");
      await page.click("button[type=&#39;submit&#39;]");
      await page.goto("http://localhost:3000");
      await expect(page.getByText("New Post")).toBeVisible();
    });
    

    What makes this an E2E test? Select all that apply.


    QUESTION 5

    In the blogging app’s CI/CD pipeline, a test fails during the pull request stage, showing that PostList doesn’t render posts correctly. Based on the lecture, what type of test is most likely running at this stage?


    QUESTION 6

    A student writes this test, thinking it’s a unit test:

    import { render, screen } from "@testing-library/react";
    import { describe, it, expect } from "vitest";
    import { PostPreview } from "../components/PostPreview";
    describe("PostPreview", () => {
      it("renders with real data", async () => {
        const response = await fetch("/api/posts");
        const post = await response.json();
        render(<PostPreview title={post[0].title} date={new Date(post[0].date)} />);
        expect(screen.getByText(post[0].title)).toBeDefined();
      });
    });
    

    What’s wrong with calling this a unit test? Select all that apply.


    QUESTION 7

    You’re testing a feature where users filter posts by date. Which approach best verifies it works across the entire app, from UI button to database query?


    QUESTION 8

    Here’s a test snippet:

    import { describe, it, expect } from "vitest";
    import { formatDate } from "../utils/date";
    describe("formatDate", () => {
      it("handles leap year dates", () => {
        const date = new Date("2024-02-29");
        expect(formatDate(date)).toBe("February 29, 2024");
      });
    });
    

    A teammate argues this should be an integration test because dates are tricky. Why is it still a unit test? Select all that apply.

    This content is only available to registered users.
    Please register at the the home page.

    QUESTION 1

    You’re debugging a test for the formatDate function in the blogging app. The test fails because it’s trying to fetch data from an API to create a Date object. Based on the lecture, what’s wrong with this test?


    QUESTION 2

    Here’s a test for the PostPreview component:

    import { render, screen } from "@testing-library/react";
    import { describe, it, expect } from "vitest";
    import { PostPreview } from "../components/PostPreview";
    describe("PostPreview", () => {
      it("renders correctly", () => {
        render(<PostPreview title="Test Post" date={new Date("2025-04-07")} />);
        expect(screen.getByText("Test Post")).toBeDefined();
        expect(screen.getByText("April 7, 2025")).toBeDefined();
      });
    });
    

    What type of test is this, and why?


    QUESTION 3

    Your team writes this test for the PostList component:

    import { render, screen } from "@testing-library/react";
    import { describe, it, expect, vi } from "vitest";
    import { PostList } from "../components/PostList";
    describe("PostList", () => {
      it("displays fetched posts", async () => {
        vi.spyOn(global, "fetch").mockResolvedValue({
          json: () => Promise.resolve([{ title: "Demo", date: "2025-04-07" }]),
        } as any);
        render(<PostList />);
        expect(await screen.findByText("Demo")).toBeDefined();
      });
    });
    

    A bug causes the PostPreview component to render the wrong date format. Will this test catch it?


    QUESTION 4

    You’re reviewing an E2E test written with Playwright:

    import { test, expect } from "@playwright/test";
    test("user adds a post", async ({ page }) => {
      await page.goto("http://localhost:3000/admin");
      await page.fill("#title", "New Post");
      await page.fill("#date", "2025-04-08");
      await page.click("button[type=&#39;submit&#39;]");
      await page.goto("http://localhost:3000");
      await expect(page.getByText("New Post")).toBeVisible();
    });
    

    What makes this an E2E test? Select all that apply.


    QUESTION 5

    In the blogging app’s CI/CD pipeline, a test fails during the pull request stage, showing that PostList doesn’t render posts correctly. Based on the lecture, what type of test is most likely running at this stage?


    QUESTION 6

    A student writes this test, thinking it’s a unit test:

    import { render, screen } from "@testing-library/react";
    import { describe, it, expect } from "vitest";
    import { PostPreview } from "../components/PostPreview";
    describe("PostPreview", () => {
      it("renders with real data", async () => {
        const response = await fetch("/api/posts");
        const post = await response.json();
        render(<PostPreview title={post[0].title} date={new Date(post[0].date)} />);
        expect(screen.getByText(post[0].title)).toBeDefined();
      });
    });
    

    What’s wrong with calling this a unit test? Select all that apply.


    QUESTION 7

    You’re testing a feature where users filter posts by date. Which approach best verifies it works across the entire app, from UI button to database query?


    QUESTION 8

    Here’s a test snippet:

    import { describe, it, expect } from "vitest";
    import { formatDate } from "../utils/date";
    describe("formatDate", () => {
      it("handles leap year dates", () => {
        const date = new Date("2024-02-29");
        expect(formatDate(date)).toBe("February 29, 2024");
      });
    });
    

    A teammate argues this should be an integration test because dates are tricky. Why is it still a unit test? Select all that apply.

    This content is only available to registered users.
    Please register at the the home page.

    Pie Logo
    Quiz: Testing Approaches
    by Tomas Trescak
    Pie Logo
    Quiz: Testing Approaches
    by Tomas Trescak
    Full Stack Development
    Introduction
    Generative AI
    🍰 Player
    💼 Editor
    Setup
    React Fundamentals
    Next.js
    Advanced React
    Databases
    React Hooks
    Authentication and Authorisation
    APIs
    CI/CD and DevOps
    Testing React
    Introduction to Testing
    Quiz: Testing Approaches
    Component Testing with React Testing Library
    Spying and Mocking
    Component Testing with Playwright
    End to End testing with Playwright
    Exercise: Testing
    Advanced Topics
    Full Stack Development
    Introduction
    Generative AI
    🍰 Player
    💼 Editor
    Setup
    React Fundamentals
    Next.js
    Advanced React
    Databases
    React Hooks
    Authentication and Authorisation
    APIs
    CI/CD and DevOps
    Testing React
    Introduction to Testing
    Quiz: Testing Approaches
    Component Testing with React Testing Library
    Spying and Mocking
    Component Testing with Playwright
    End to End testing with Playwright
    Exercise: Testing
    Advanced Topics