-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from towa-digital/feature/update-tests
Feature: Setup test with Typescript
- Loading branch information
Showing
5 changed files
with
243 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
|
||
|
||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
Oops, something went wrong.