Testing Guide

Learn about testing practices and tools in Gconv Prune

Testing Stack

  • Jest - Unit testing framework
  • React Testing Library - Component testing
  • Cypress - End-to-end testing
  • MSW - API mocking

Unit Testing Example

Example of a unit test using Jest:

import { validateInput } from "./utils";

describe("validateInput", () => {
  it("should return true for valid input", () => {
    const input = {
      name: "John",
      email: "[email protected]"
    };
    expect(validateInput(input)).toBe(true);
  });

  it("should return false for invalid input", () => {
    const input = {
      name: "",
      email: "invalid-email"
    };
    expect(validateInput(input)).toBe(false);
  });
});

Component Testing

Example of testing a React component:

import { render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { Button } from "./Button";

describe("Button", () => {
  it("should call onClick when clicked", async () => {
    const onClick = jest.fn();
    render(<Button onClick={onClick}>Click me</Button>);
    
    await userEvent.click(screen.getByText("Click me"));
    expect(onClick).toHaveBeenCalled();
  });
});

E2E Testing

Example of an end-to-end test using Cypress:

describe("Authentication", () => {
  it("should allow user to log in", () => {
    cy.visit("/login");
    cy.get("[data-testid=email]").type("[email protected]");
    cy.get("[data-testid=password]").type("password123");
    cy.get("[data-testid=submit]").click();
    cy.url().should("include", "/dashboard");
  });
});

Test Coverage

Coverage requirements:

  • Unit tests: 80% coverage
  • Integration tests: Key user flows
  • E2E tests: Critical business paths
  • Visual regression: Core components

Need Help?

For testing help, check our troubleshooting guide or contact our support team.