@traversable/schema
    Preparing search index...

    Module @traversable/typebox-test - v0.0.20


    ᯓ𝘁𝗿𝗮𝘃𝗲𝗿𝘀𝗮𝗯𝗹𝗲/𝘁𝘆𝗽𝗲𝗯𝗼𝘅-𝘁𝗲𝘀𝘁


    Testing utility that generates arbitrary, pseudorandom TypeBox schemas, powered by fast-check

    NPM Version   TypeScript   License   npm  


    @traversable/typebox-test has 2 peer dependencies:

    1. @sinclair/typebox (v0.34)
    2. fast-check
    $ pnpm add -D @traversable/typebox-test @sinclair/typebox fast-check
    

    Here's an example of importing the library:

    import * as T from '@sinclair/typebox'
    import { boxTest } from '@traversable/typebox-test'

    // see below for specifc examples

    Use boxTest.seedToSchema to convert a seed generated by boxTest.SeedGenerator into a TypeBox schema that satisfies the configuration options you specified.

    import * as T from '@sinclair/typebox'
    import { boxTest } from '@traversable/typebox-test'
    import * as fc from 'fast-check'

    const builder = boxTest.SeedGenerator()['*']
    const [mySeed] = fc.sample(builder.object, 1)

    const mySchema = boxTest.seedToSchema(mySeed)
    // ^? const mySchema: T.TSchema

    Use boxTest.seedToValidData to convert a seed generated by boxTest.SeedGenerator into data that satisfies the schema that the seed represents.

    import * as T from '@sinclair/typebox'
    import * as Value from '@sinclair/typebox/value'
    import { boxTest } from '@traversable/typebox-test'
    import * as fc from 'fast-check'

    const builder = boxTest.SeedGenerator()['*']
    const [mySeed] = fc.sample(builder.object, 1)

    const mySchema = boxTest.seedToSchema(mySeed)
    // ^? const mySchema: T.TSchema

    const validData = boxTest.seedToValidData(mySeed)

    Value.Check(mySchema, validData) // always `true`

    Use boxTest.seedToInvalidData to convert a seed generated by boxTest.SeedGenerator into data that does not satisfy the schema that the seed represents.

    import * as T from '@sinclair/typebox'
    import * as Value from '@sinclair/typebox/value'
    import { boxTest } from '@traversable/typebox-test'
    import * as fc from 'fast-check'

    const builder = boxTest.SeedGenerator()['*']
    const [mySeed] = fc.sample(builder.object, 1)

    const mySchema = boxTest.seedToSchema(mySeed)
    // ^? const mySchema: T.TSchema

    const invalidData = boxTest.seedToValidData(mySeed)

    Value.Check(mySchema, invalidData) // always `false`
    Note

    boxTest.SeedGenerator is fairly low-level. All of the other exports of this library have been implemented in terms of boxTest.SeedGenerator.

    Generates a configurable, pseudo-random "seed builder".

    import { type } from '@sinclair/typebox'
    import * as fc from 'fast-check'
    import { boxTest } from '@traversable/typebox-test'

    const builder = boxTest.SeedGenerator({
    include: ["boolean", "string", "object"],
    // 𐙘 use `include` to only include certain schema types
    exclude: ["boolean", "any"],
    // 𐙘 use `exclude` to exclude certain schema types altogether (overrides `include`)
    object: { maxKeys: 5 },
    // 𐙘 specific arbitraries are configurable by name
    })

    // included schemas are present as properties on your generator...
    builder.string
    builder.object

    // ...excluded schemas are not present...
    builder.boolean // 🚫 TypeError

    // ...a special wildcard `"*"` property (pronounced "surprise me") is always present:
    builder["*"]

    /**
    * `fast-check` will generate a seed, which is a data structure containing
    * integers that represent a kind of AST.
    *
    * To use a seed, you need to pass it to an interpreter like `boxTest.seedToSchema`,
    * `boxTest.seedToValidData` or `boxTest.seedToInvalidData`:
    */

    const [mySeed] = fc.sample(builder.object, 1)

    const mySchema = boxTest.seedToSchema(mySeed)
    // ^? const mySchema: type.Any

    const validData = boxTest.seedToValidData(mySeed)
    // ^? since the `mySeed` was also used to generate `mySchema`,
    // parsing `validData` should always succeed

    const invalidData = boxTest.seedToInvalidData(mySeed)
    // ^? since the `mySeed` was also used to generate `mySchema`,
    // parsing `invalidData` should always fail

    Like boxTest.SeedGenerator, except boxTest.SeedValidDataGenerator comes pre-configured to exclude schemas that make it impossible to reliably generate valid data.

    Note

    boxTest.SeedValidDataGenerator does not accept any options. If you need more fine-grained control of the schemas being generated, use boxTest.SeedGenerator.

    Like boxTest.SeedGenerator, except boxTest.SeedValidDataGenerator comes pre-configured to exclude schemas that make it impossible to reliably generate invalid data.

    Note

    boxTest.SeedInvalidDataGenerator does not accept any options. If you need more fine-grained control of the schemas being generated, use boxTest.SeedGenerator.

    Namespaces

    boxTest
    Gen
    SchemaGenerator
    Seed

    Interfaces

    Builder
    SeedBuilder
    SeedMap

    Type Aliases

    Seed
    VERSION

    Variables

    SchemaGenerator
    SeedGenerator
    SeedInvalidDataGenerator
    SeedMap
    seedToInvalidData
    seedToValidData
    SeedValidDataGenerator
    VERSION

    Functions

    Builder
    Gen
    seedToInvalidDataGenerator
    seedToSchema
    seedToValidDataGenerator