Skip to main content

@lexical/fast-check

Functions

nodeArbitrary()

nodeArbitrary<T>(klass): Arbitrary<LexicalSchemaInput<T>>

Defined in: packages/lexical-fast-check/src/index.ts:48

Derive a fast-check arbitrary for the node-specific properties of klass's serialized JSON, composing the schemas it inherits — so an element-based node generates the properties it gets from ElementNode as well as its own. Spread the result with type/version to feed importJSON. Because each property's schema is the same one the node uses to parse its JSON, the generated values are exactly what the node's parser accepts — a single declaration powers both parsing and example generation.

Every property is generated independently as present or absent (requiredKeys: []), because that is the domain the parsers actually face: a SerializedPartial may omit any node-specific property — older documents predate a property, and a compact export omits one whose value equals its default. Generating complete records only would leave the defaulting path (the whole point of a schema carrying a defaultValue) untested.

The values are typed as what the class's schemas accept, composed across its $config chain — not as what they parse to. The two differ wherever a schema reads more than it writes, and this generator produces exactly that difference: an aliasedValue's legacy spellings are in the generated domain (see the aliased case below), so a type describing the parsed output would be wrong about the values it hands back.

Type Parameters

T

T extends LexicalNode

Parameters

klass

Klass<T>

Returns

Arbitrary<LexicalSchemaInput<T>>