Functions
Vitest component test integration
Vitest and React Testing Library are ecosystem tools. Configure jsdom and the React transform; install reviewed user-event and arrange DOM cleanup. This test assumes Quantity starts at one and caps at three. Async Server Components need integration or browser testing, not a synchronous render substitute. Source: https://nextjs.org/docs/app/guides/testing/vitest. Documentation-reviewed illustrative draft; installed declarations and runtime not verified.
Formal Syntax & Structure
nextjs syntaxnextjs
test(name, async () => { ... })Working Example
Example Snippetnextjs
// tests/quantity.test.tsximport {test,expect} from 'vitest';import {render,screen} from '@testing-library/react';import userEvent from '@testing-library/user-event';import Quantity from '../app/quantity';test('stops at three',async()=>{ render(<Quantity/>);const user=userEvent.setup(); const add=screen.getByRole('button',{name:'Add one'}); await user.click(add);await user.click(add); expect(screen.getByRole('status').textContent).toBe('3 selected'); expect((add as HTMLButtonElement).disabled).toBe(true);});