Rocky_Mountain_Vending/.pnpm-store/v10/files/0c/430ace4f09dc2375e34a370b4591ca23038ad900045be94639b0d393272ab3ae2d4bc19a485a4bd342e425d1a559abdd16d11769b1aa71614d1625bb901f50
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

45 lines
1.6 KiB
Text

import { act, renderHook } from "@testing-library/react";
import { useControlledValue } from "./useControlledValue";
describe("when the value is controlled", () => {
const defaultValue: string | undefined = "foo"; // not controlled
const controlledValue: string | undefined = "bar"; // now controlled
test("should return the controlled value", () => {
const { result } = renderHook(() =>
useControlledValue<string>(defaultValue, controlledValue)
);
expect(result.current[0]).toBe(controlledValue);
});
describe("when setting a new value", () => {
const newValue = "taz";
test("should return the controlled value instead", async () => {
const { result } = renderHook(() =>
useControlledValue<string>(defaultValue, controlledValue)
);
act(() => result.current[1](newValue));
expect(result.current[0]).toBe(controlledValue);
});
});
});
describe("when the value is not controlled", () => {
const defaultValue = "foo";
const controlledValue = undefined;
test("should return the value", () => {
const { result } = renderHook(() =>
useControlledValue<string>(defaultValue, controlledValue)
);
expect(result.current[0]).toBe(defaultValue);
});
describe("when setting a new value", () => {
const newValue = "bar";
test("should return the new value", async () => {
const { result } = renderHook(() =>
useControlledValue<string>(defaultValue, controlledValue)
);
act(() => result.current[1](newValue));
expect(result.current[0]).toBe(newValue);
});
});
});