-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b36d0e9
commit a10afa8
Showing
2 changed files
with
11 additions
and
35 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,37 +1,10 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import Form from "../../components/Form" | ||
|
||
jest.mock('../../components/Form', () => ({ | ||
__esModule: true, | ||
default: jest.fn(), | ||
})); | ||
|
||
const mockPost = { | ||
prompt: '', | ||
tag: '', | ||
}; | ||
|
||
const mockSubmitHandler = jest.fn(); | ||
|
||
test('renders the Form component with placeholders', () => { | ||
Form.mockImplementationOnce(() => ( | ||
<Form type="Create" post={mockPost} setPost={() => {}} submitting={false} handleSubmit={mockSubmitHandler} /> | ||
)); | ||
render(<Form />); // You can render directly without props here | ||
|
||
// Assertions using screen.getByText, screen.getByPlaceholderText, etc. | ||
expect(screen.getByText(/Create Post/i)).toBeInTheDocument(); | ||
expect(screen.getByPlaceholderText(/Write Your Prompt Here.../i)).toBeInTheDocument(); | ||
expect(screen.getByText(/Field of Prompt/i)).toBeInTheDocument(); | ||
}); | ||
|
||
test('disables submit button when submitting is true', () => { | ||
Form.mockImplementationOnce(() => ( | ||
<Form type="Create" post={mockPost} setPost={() => {}} submitting={true} handleSubmit={mockSubmitHandler} /> | ||
)); | ||
render(<Form />); | ||
|
||
const submitButton = screen.getByRole('button', { name: /Create/i }); | ||
expect(submitButton).toBeDisabled(); | ||
}); | ||
import { Form } from '@/components'; | ||
|
||
describe("Form Components", () => { | ||
it("should render Form Component", () => { | ||
expect(Form).toBeDefined() | ||
expect(Form).toMatchSnapshot() | ||
}) | ||
}) |
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,3 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Form Components should render Form Component 1`] = `[Function]`; |