Type alias EngineType<Queries, Callbacks, Properties, Hooks>

EngineType<Queries, Callbacks, Properties, Hooks>: {
    accessors: {
        [Key in keyof Queries]: AccessorsType<Queries[Key]>
    };
    checkIsRendered: (() => boolean);
    getCallback: (<Key>(callbackKey) => Function & ComponentProps<Queries[Callbacks[Key][0]]>[Callbacks[Key][1]]);
    getHookArguments: (<Key>(hookKey) => Parameters<Hooks[Key]>);
    getProperty: (<Key>(propertyKey) => ComponentProps<Queries[Properties[Key][0]]>[Properties[Key][1]]);
    root: ReactElement | null | undefined;
}

Type Parameters

  • Queries extends Record<string, keyof JSX.IntrinsicElements | ComponentType<any>>

  • Callbacks extends Record<string, [keyof Queries & string, string]>

  • Properties extends Record<string, [keyof Queries, string]>

  • Hooks extends Record<string, ((...args) => any)>

Type declaration

  • accessors: {
        [Key in keyof Queries]: AccessorsType<Queries[Key]>
    }

    An object whose keys are keys of the queries parameter and whose values are accessors in the format of react-shallow-search

    const render = create(Component, defaultProps, {
    queries: {
    fooButton: {
    component: 'button',
    className: 'foo',
    },
    },
    });

    const engine = render({});

    const fooButtonProps = page.accessors.fooButton.getProps();
  • checkIsRendered: (() => boolean)
      • (): boolean
      • Check if any react elements are rendered

        Returns boolean

  • getCallback: (<Key>(callbackKey) => Function & ComponentProps<Queries[Callbacks[Key][0]]>[Callbacks[Key][1]])
      • <Key>(callbackKey): Function & ComponentProps<Queries[Callbacks[Key][0]]>[Callbacks[Key][1]]
      • Get callback from parameters by the key

        Type Parameters

        • Key extends keyof Callbacks & string

        Parameters

        • callbackKey: Key

          a key of the callbacks parameter

        Returns Function & ComponentProps<Queries[Callbacks[Key][0]]>[Callbacks[Key][1]]

        callback by paramteres of the callbacks[callbackKey]

        Throws

        if callbacks parameter is not setted

        Throws

        if the property value is not a function

        const render = create(Component, defaultProps, {
        queries: {
        fooButton: {
        component: 'button',
        className: 'foo',
        },
        },

        callbacks: {
        onFooClick: ['fooButton', 'onClick'],
        },
        });

        const engine = render({});

        page.getCallback('onFooClick')({} as MouseEvent);
  • getHookArguments: (<Key>(hookKey) => Parameters<Hooks[Key]>)
      • <Key>(hookKey): Parameters<Hooks[Key]>
      • Get the arguments of the called hook function

        Type Parameters

        • Key extends keyof Hooks

        Parameters

        • hookKey: Key

          a key of the hooks parameter

        Returns Parameters<Hooks[Key]>

        the arguments with which the hook by key was called

        Throws

        if hooks not setted

        Throws

        if hookOrder not setted

        Throws

        if mockFunctionValue not setted

        Throws

        if getMockArguments not setted

        import { vi } from "vitest";

        function Component() {
        const [counter, setCounter] = useState(0);

        // ...
        }

        const render = create(Component, defaultProps, {
        queries: {},
        hooks: {
        counter: useState,
        },
        hookOrder: [
        "counter",
        ],
        mockFunctionValue: (fn, value) => {
        vi.mocked(fn).mockReturnValueOnce(value);
        },
        getMockArguments: (fn, callIndex) => {
        return vi.mocked(fn).mock.calls[callIndex];
        },
        });

        const engine = render({});

        assert.strictEqual(
        engine.getHookArguments("counter"),
        0,
        );
  • getProperty: (<Key>(propertyKey) => ComponentProps<Queries[Properties[Key][0]]>[Properties[Key][1]])
      • <Key>(propertyKey): ComponentProps<Queries[Properties[Key][0]]>[Properties[Key][1]]
      • Get prop value from parameters by the key

        Type Parameters

        • Key extends keyof Properties & string

        Parameters

        • propertyKey: Key

          a key of the properties parameter

        Returns ComponentProps<Queries[Properties[Key][0]]>[Properties[Key][1]]

        value by paramteres of the properties[propertyKey]

        const render = create(Component, defaultProps, {
        queries: {
        content: {
        component: 'div',
        className: 'foo',
        },
        },

        properties: {
        contentChildren: ['content', 'children'],
        },
        });

        const engine = render({});

        const contentChildren = page.getProperty('contentChildren');
  • root: ReactElement | null | undefined

    Root node of rendered react tree

Generated using TypeDoc