Rocky_Mountain_Vending/.pnpm-store/v10/files/bf/a28ba1501aafd673314cdc40a74a6c5f716b213c63c15ee98147cab113426f827478784ffd47d34cbac900f8ece1267ea8f73b575b61d9a97868eddc3b81d6
DMleadgen 46d973904b
Initial commit: Rocky Mountain Vending website
Next.js website for Rocky Mountain Vending company featuring:
- Product catalog with Stripe integration
- Service areas and parts pages
- Admin dashboard with Clerk authentication
- SEO optimized pages with JSON-LD structured data

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-12 16:22:15 -07:00

60 lines
1.7 KiB
Text

import { render, screen } from '@testing-library/react';
import user from '@testing-library/user-event';
import React from 'react';
import { useForm } from 'react-hook-form';
import * as vest from 'vest';
import { vestResolver } from '..';
interface FormData {
username: string;
password: string;
}
const validationSuite = vest.create('form', (data: FormData) => {
vest.test('username', 'Username is required', () => {
vest.enforce(data.username).isNotEmpty();
});
vest.test('password', 'Password must contain a symbol', () => {
vest.enforce(data.password).matches(/[^A-Za-z0-9]/);
});
});
interface Props {
onSubmit: (data: FormData) => void;
}
function TestComponent({ onSubmit }: Props) {
const {
register,
formState: { errors },
handleSubmit,
} = useForm<FormData>({
resolver: vestResolver(validationSuite), // Useful to check TypeScript regressions
});
return (
<form onSubmit={handleSubmit(onSubmit)}>
<input {...register('username')} />
{errors.username && <span role="alert">{errors.username.message}</span>}
<input {...register('password')} />
{errors.password && <span role="alert">{errors.password.message}</span>}
<button type="submit">submit</button>
</form>
);
}
test("form's validation with Vest and TypeScript's integration", async () => {
const handleSubmit = vi.fn();
render(<TestComponent onSubmit={handleSubmit} />);
expect(screen.queryAllByRole('alert')).toHaveLength(0);
await user.click(screen.getByText(/submit/i));
expect(screen.getByText(/Username is required/i)).toBeVisible();
expect(screen.getByText(/Password must contain a symbol/i)).toBeVisible();
expect(handleSubmit).not.toHaveBeenCalled();
});