Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

1.1 KB
Raw Blame
/* Copyright 2026 Marimo. All rights reserved. */

import { act, renderHook } from "@testing-library/react";
import { describe, expect, it, vi } from "vitest";
import { useBoolean } from "../useBoolean";

describe("useBoolean", () => {
  it("should initialize with given value", () => {
    const { result } = renderHook(() => useBoolean(true));
    expect(result.current[0]).toBe(true);
  });

  it("should toggle value", () => {
    const { result } = renderHook(() => useBoolean(false));
    act(() => result.current[1].toggle());
    expect(result.current[0]).toBe(true);
  });

  it("should set true/false", () => {
    const { result } = renderHook(() => useBoolean(false));
    act(() => result.current[1].setTrue());
    expect(result.current[0]).toBe(true);
    act(() => result.current[1].setFalse());
    expect(result.current[0]).toBe(false);
  });

  it("should handle event.stopPropagation", () => {
    const { result } = renderHook(() => useBoolean(false));
    const mockEvent = { stopPropagation: vi.fn() };
    act(() => result.current[1].setTrue(mockEvent));
    expect(mockEvent.stopPropagation).toHaveBeenCalled();
  });
});