Skip to content

Commit 3f586b6

Browse files
committed
Visual regression test
1 parent 822f44b commit 3f586b6

9 files changed

+29
-21
lines changed

cypress/integration/home-page.spec.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1-
import {
2-
smallBreakpoint,
3-
mediumBreakpoint,
4-
largeBreakpoint,
5-
} from "@/utils/constants";
1+
import { breakpointList } from "@/utils/constants";
62

7-
describe("The Home Page", () => {
8-
it("successfully loads homepage", () => {
3+
describe("Home page", () => {
4+
it("should successfully load", () => {
95
cy.visit("/");
10-
cy.matchImageSnapshot();
6+
});
7+
8+
breakpointList.forEach((width) => {
9+
it(`should match current snapshot ('${width}px' viewport width)`, () => {
10+
cy.viewport(width, 1080);
11+
cy.visit(`/`);
12+
cy.matchImageSnapshot();
13+
});
1114
});
1215
});
Loading
Loading

jest/jest.setup.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import { expect } from "@jest/globals";
22
import "@testing-library/jest-dom";
33
import { configureToMatchImageSnapshot } from "jest-image-snapshot";
4+
import { setDefaultOptions } from "jsdom-screenshot";
5+
6+
setDefaultOptions({
7+
launch: {},
8+
});
49

510
const toMatchImageSnapshot = configureToMatchImageSnapshot({
611
customSnapshotsDir: "jest/snapshots/current_output",

src/components/welcome/welcome.test.tsx

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@ import { render } from "@testing-library/react";
33
import { generateImage } from "jsdom-screenshot";
44
import Welcome from "@/components/welcome/welcome";
55

6-
test("should render text", () => {
7-
const { rerender, getByText } = render(<Welcome />);
8-
expect(getByText("Welcome to Next.js!")).toBeInTheDocument();
9-
rerender(<Welcome showCarrot={true} />);
10-
expect(getByText("Welcome to Next.js! 🥕")).toBeInTheDocument();
11-
});
6+
describe("Welcome component", () => {
7+
it("should render text", () => {
8+
const { rerender, getByText } = render(<Welcome />);
9+
expect(getByText("Welcome to Next.js!")).toBeInTheDocument();
10+
rerender(<Welcome showCarrot={true} />);
11+
expect(getByText("Welcome to Next.js! 🥕")).toBeInTheDocument();
12+
});
1213

13-
test("should match image snapshot", async () => {
14-
render(<Welcome />);
15-
expect(await generateImage()).toMatchImageSnapshot();
14+
it("should match current snapshot", async () => {
15+
render(<Welcome />);
16+
expect(await generateImage()).toMatchImageSnapshot();
17+
});
1618
});

src/utils/constants.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
export const smallBreakpoint = 640;
2-
export const mediumBreakpoint = 768;
1+
export const smallBreakpoint = 480;
32
export const largeBreakpoint = 1024;
3+
export const breakpointList = [smallBreakpoint, largeBreakpoint];

tsconfig.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,5 @@
3030
],
3131
"exclude": [
3232
"node_modules",
33-
"**/*.test.ts",
34-
"**/*.test.tsx"
3533
]
3634
}

0 commit comments

Comments
 (0)