Verwendung

Inspect a native property value.

tsx
// Inspect a native property value.
import { Button, Show, Text, VStack, signal } from 'kuito';
import { assert, press, render, screen, test, type PropValue } from 'kuito/tests';

function Alarm() {
  const armed = signal(false);

  return (
    <VStack>
      <Show when={armed.value}>
        <Text color="#ff3b30">Armed</Text>
      </Show>
      <Button onPress={() => (armed.value = true)}>Arm</Button>
    </VStack>
  );
}

// A color crosses as a 0xRRGGBBAA number.
const red: PropValue = { type: 'color', value: 0xff3b30ff };

test('arming shows a red warning', async () => {
  const app = await render(<Alarm />);
  const before = app.mutations.length;

  await press(screen.getByText('Arm'));

  const color = app.mutations
    .slice(before)
    .find((mutation) => mutation.op === 'prop' && mutation.name === 'color');

  assert.equal(color?.op === 'prop' && color.value, red.value);
});

Typdeklaration

ts
export type PropValue =
  | { type: 'null'; value: null }
  | { type: 'number'; value: number | null }
  | { type: 'boolean'; value: boolean }
  | { type: 'text' | 'json'; value: string }
  /** Its index among the prop's manifest values, and the value as written. */
  | { type: 'enum'; value: string; index: number }
  /** 0xRRGGBBAA. */
  | { type: 'color'; value: number }
  | { type: 'keys'; value: KeyEdit[] }
  /** A structured prop's value as the kernel wrote it, checked against its schema. */
  | { type: 'struct'; value: unknown };

Mitglieder 2

NameTypErforderlichBeschreibung
type"number" | "boolean" | "color" | "text" | "keys" | "null" | "json" | "enum" | "struct"Ja—
valueunknownJa—
Generiert aus den öffentlichen TypeScript-Deklarationen: Signaturen, Props und Standardwerte stammen aus der geprüften Quelle, Beschreibungen aus deren JSDoc. Kein Standardwert ist erfunden.