Skip to content

Commit

Permalink
Merge pull request #2 from towa-digital/feature/update-tests
Browse files Browse the repository at this point in the history
Feature: Setup test with Typescript
  • Loading branch information
mattcrn authored Sep 16, 2024
2 parents 086a4bb + 968f848 commit b540e1b
Show file tree
Hide file tree
Showing 5 changed files with 243 additions and 49 deletions.
39 changes: 19 additions & 20 deletions __tests__/Button.test.js → __tests__/Button.test.tsx
Original file line number Diff line number Diff line change
@@ -1,36 +1,35 @@
import React from 'react';
import { render, screen, fireEvent } from '@testing-library/react';
import Button from '../src/components/ui/Button';
import '@testing-library/jest-dom';

test('renders button with provided label and icon', () => {
const label = 'Test Button';
const iconText = 'Icon';
import { render, screen, fireEvent } from "@testing-library/react";
import Button from "@/components/ui/Button";
import "@testing-library/jest-dom";

describe("Button", () => {
test("renders with provided label and icon", () => {
const label = "Test Button";
const iconText = "Icon";
const icon = <span data-testid="icon">{iconText}</span>;

render(<Button label={label} icon={icon} />);

// Verify that the label is rendered (considering screen-reader-only classes)
const labelElement = screen.getByText(label);
expect(labelElement).toBeInTheDocument();

// Verify that the icon is rendered
const iconElement = screen.getByTestId('icon');
const iconElement = screen.getByTestId("icon");
expect(iconElement).toBeInTheDocument();
expect(iconElement).toHaveTextContent(iconText);
});

test('calls onPress handler when button is clicked', () => {
test("calls onPress handler when Button is clicked", () => {
const handlePress = jest.fn();
const label = 'Click Me';
const label = "Click Me";
const icon = <span>Icon</span>;

render(<Button label={label} icon={icon} onPress={handlePress} />);
const buttonElement = screen.getByRole('button');

const buttonElement = screen.getByRole("button");
fireEvent.click(buttonElement);

expect(handlePress).toHaveBeenCalledTimes(1);
});


});
12 changes: 0 additions & 12 deletions jest.config.js

This file was deleted.

20 changes: 20 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* For a detailed explanation regarding each configuration property, visit:
* https://jestjs.io/docs/configuration
*/
import type { Config } from "jest";
import nextJest from "next/jest.js";

const createJestConfig = nextJest({
dir: "./",
});

const config: Config = {
clearMocks: true,
collectCoverage: true,
coverageDirectory: "coverage",
coverageProvider: "v8",
testEnvironment: "jsdom",
};

export default createJestConfig(config);
Loading

0 comments on commit b540e1b

Please # to comment.