Skip to content

Commit

Permalink
Visual regression test
Browse files Browse the repository at this point in the history
  • Loading branch information
osheinonen committed Jul 14, 2021
1 parent 822f44b commit 3f586b6
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 21 deletions.
19 changes: 11 additions & 8 deletions cypress/integration/home-page.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import {
smallBreakpoint,
mediumBreakpoint,
largeBreakpoint,
} from "@/utils/constants";
import { breakpointList } from "@/utils/constants";

describe("The Home Page", () => {
it("successfully loads homepage", () => {
describe("Home page", () => {
it("should successfully load", () => {
cy.visit("/");
cy.matchImageSnapshot();
});

breakpointList.forEach((width) => {
it(`should match current snapshot ('${width}px' viewport width)`, () => {
cy.viewport(width, 1080);
cy.visit(`/`);
cy.matchImageSnapshot();
});
});
});
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
5 changes: 5 additions & 0 deletions jest/jest.setup.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { expect } from "@jest/globals";
import "@testing-library/jest-dom";
import { configureToMatchImageSnapshot } from "jest-image-snapshot";
import { setDefaultOptions } from "jsdom-screenshot";

setDefaultOptions({
launch: {},
});

const toMatchImageSnapshot = configureToMatchImageSnapshot({
customSnapshotsDir: "jest/snapshots/current_output",
Expand Down
20 changes: 11 additions & 9 deletions src/components/welcome/welcome.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ import { render } from "@testing-library/react";
import { generateImage } from "jsdom-screenshot";
import Welcome from "@/components/welcome/welcome";

test("should render text", () => {
const { rerender, getByText } = render(<Welcome />);
expect(getByText("Welcome to Next.js!")).toBeInTheDocument();
rerender(<Welcome showCarrot={true} />);
expect(getByText("Welcome to Next.js! 🥕")).toBeInTheDocument();
});
describe("Welcome component", () => {
it("should render text", () => {
const { rerender, getByText } = render(<Welcome />);
expect(getByText("Welcome to Next.js!")).toBeInTheDocument();
rerender(<Welcome showCarrot={true} />);
expect(getByText("Welcome to Next.js! 🥕")).toBeInTheDocument();
});

test("should match image snapshot", async () => {
render(<Welcome />);
expect(await generateImage()).toMatchImageSnapshot();
it("should match current snapshot", async () => {
render(<Welcome />);
expect(await generateImage()).toMatchImageSnapshot();
});
});
4 changes: 2 additions & 2 deletions src/utils/constants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export const smallBreakpoint = 640;
export const mediumBreakpoint = 768;
export const smallBreakpoint = 480;
export const largeBreakpoint = 1024;
export const breakpointList = [smallBreakpoint, largeBreakpoint];
2 changes: 0 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,5 @@
],
"exclude": [
"node_modules",
"**/*.test.ts",
"**/*.test.tsx"
]
}

0 comments on commit 3f586b6

Please sign in to comment.