// // Copyright 2026 DXOS.org // import { cleanup, render, screen } from '@testing-library/react'; import React from 'react'; import { afterEach, describe, expect, test } from 'vitest'; import * as Match from './Match.tsx'; describe('Match', () => { afterEach(cleanup); test('renders the branch whose `when` strictly equals `on`', () => { render(
, ); expect(screen.queryByTestId('a')).toBeNull(); expect(screen.queryByTestId('b')).not.toBeNull(); }); test('renders only the first of several matching branches', () => { render(
, ); expect(screen.queryByTestId('first')).not.toBeNull(); expect(screen.queryByTestId('second')).toBeNull(); }); test('strict equality does not coerce', () => { render( }>
, ); expect(screen.queryByTestId('coerced')).toBeNull(); expect(screen.queryByTestId('fallback')).not.toBeNull(); }); test('predicate `when` matches on the discriminant', () => { render( value < 3}>
value >= 3}>
, ); expect(screen.queryByTestId('low')).toBeNull(); expect(screen.queryByTestId('high')).not.toBeNull(); }); test('no match and no fallback renders nothing', () => { const { container } = render(
, ); expect(container.innerHTML).toBe(''); }); test('non-Match children are ignored', () => { render( }>
, ); expect(screen.queryByTestId('stray')).toBeNull(); expect(screen.queryByTestId('fallback')).not.toBeNull(); }); test('adds no wrapper element', () => { const { container } = render(
, ); expect(container.firstElementChild?.getAttribute('data-testid')).toBe('a'); }); });