@instructure/ui-test-utils

  • Version 8.24.2
  • Published
  • 214 kB
  • 12 dependencies
  • MIT license

Install

npm i @instructure/ui-test-utils
yarn add @instructure/ui-test-utils
pnpm add @instructure/ui-test-utils

Overview

A UI testing library made by Instructure Inc.

Index

Variables

variable expect

const expect: Chai.ExpectStatic;

    variable wait

    const wait: (
    callback?: () => void,
    { timeout, interval }?: { timeout?: number; interval?: number }
    ) => Promise<{}>;

      variable within

      const within: any;

        variable wrap

        const wrap: any;

          Functions

          function generateA11yTests

          generateA11yTests: <Props>(
          Component: React.ComponentType<any>,
          componentExample: StoryConfig<Props>,
          ariaRulesToIgnore?: string[]
          ) => void;
          • This function will generate a11y tests based on the component and the component example definition json. It will enumerate over the generated component examples and will call the .accessible() function on it.

            const subject = await mount(<Example />)
            const element = within(subject.getDOMNode())
            expect(await element.accessible()).to.be.true()

            Parameter Component

            The base Component

            Parameter componentExample

            The example definition json, this will be the basis for the prop combination generation.

            Parameter ariaRulesToIgnore

            ARIA rules to ignore. these must be one of the rules described here: https://dequeuniversity.com/rules/axe/4.4

            generateA11yTests

          function generateComponentExamples

          generateComponentExamples: <Props>(
          Component: ComponentType<any>,
          config: StoryConfig<Props>
          ) => ExampleSection<Props>[];
          • Generates examples for the given component based on the given configuration.

            Parameter Component

            A React component

            Parameter config

            A configuration object (stored in xy.examples.jsx files in InstUI)

            Returns

            Array of examples broken into sections and pages if configured to do so. generateComponentExamples

          function generatePropCombinations

          generatePropCombinations: <T>(
          propValues: Props<T>
          ) => Record<keyof Props<T>, ArrayElement<Props<T>[keyof Props<T>]>>[];
          • Given possible values for each prop, returns all combinations of those prop values. To generate the prop names and values from the component source see the parsePropValues utility

            Parameter propValues

            an object with the shape {propName: arrayOfPossibleValues}

            Returns

            {Array} an array of all prop combinations [{propAName: propAValue, propBName: propBValue}]

            generatePropCombinations

          function waitForExpect

          waitForExpect: (
          callback?: () => void,
          {
          timeout,
          interval,
          }?: { timeout?: number | undefined; interval?: number | undefined }
          ) => Promise<{}>;

            Type Aliases

            type Example

            type Example<Props> = {
            Component: ComponentType;
            componentProps: Partial<Props>;
            exampleProps: Record<string, any>;
            key: string;
            };

              type ExamplesPage

              type ExamplesPage<Props> = {
              examples: Example<Props>[];
              index: number;
              renderExample?: (exampleProps: Example<Props>) => ReactNode;
              parameters?: Record<string, unknown>;
              };

                type StoryConfig

                type StoryConfig<Props> = {
                /**
                * Used to divide the resulting examples into sections. It should correspond
                * to an enumerated prop in the Component
                */
                sectionProp?: keyof Props;
                /**
                * Specifies the max number of examples that can exist in a single page
                * within a section
                */
                maxExamplesPerPage?: number | ((sectionName: string) => number);
                /**
                * Specifies the total max number of examples. Default: 500
                */
                maxExamples?: number;
                /**
                * An object with keys that correspond to the component props. Each key has a
                * corresponding value array. This array contains possible values for that prop.
                */
                propValues?: Partial<Record<keyof Props | string, any[]>>;
                /**
                * Prop keys to exclude from propValues. Useful when generating propValues with code.
                */
                excludeProps?: (keyof Props)[];
                /**
                * The values returned by this function are passed to the component.
                * A function called with the prop combination for the current example. It
                * returns an object of props that will be passed into the `renderExample`
                * function as componentProps.
                */
                getComponentProps?: (props: Props & Record<string, any>) => Partial<Props>;
                /**
                * The values returned by this function are passed to a `View` that wraps the
                * example.
                * A function called with the prop combination for the current example. It
                * returns an object of props that will be passed into the `renderExample`
                * function as exampleProps.
                */
                getExampleProps?: (props: Props & Record<string, any>) => Record<string, any>;
                /**
                * A function called with the examples and index for the current page of
                * examples. It returns an object of parameters/metadata for that page of
                * examples (e.g. to be passed in to a visual regression tool like chromatic).
                */
                getParameters?: (params: ExamplesPage<Props>) => {
                [key: string]: any;
                delay?: number;
                disable?: boolean;
                };
                filter?: (props: Props) => boolean;
                };

                  Namespaces

                  namespace global

                  namespace global {}

                    namespace global.Chai

                    namespace global.Chai {}

                      interface Assertion

                      interface Assertion {}

                        property contain

                        readonly contain: Assertion;

                          method accessible

                          accessible: { (): boolean; (): boolean };

                            method ancestors

                            ancestors: { (expected: string): void; (expected: string): void };

                              method attribute

                              attribute: {
                              (expectedAttribute: string, expectedAttributeValue?: string): void;
                              (expectedAttribute: string, expectedAttributeValue?: string): void;
                              };

                                method bounds

                                bounds: {
                                (expected: string, expectedAttributeValue?: string | number): void;
                                (expected: string, expectedAttributeValue?: string | number): void;
                                };

                                  method checked

                                  checked: { (): boolean; (): boolean };

                                    method children

                                    children: { (expected: string): void; (expected: string): void };

                                      method className

                                      className: { (expected: string): void; (expected: string): void };

                                        method clickable

                                        clickable: { (): boolean; (): boolean };

                                          method descendants

                                          descendants: { (expected: string): void; (expected: string): void };

                                            method disabled

                                            disabled: { (): boolean; (): boolean };

                                              method enabled

                                              enabled: { (): boolean; (): boolean };

                                                method exactly

                                                exactly: { (expected: number): Assertion; (expected: number): Assertion };

                                                  method focus

                                                  focus: { (): boolean; (): boolean };

                                                    method focusable

                                                    focusable: { (): boolean; (): boolean };

                                                      method focused

                                                      focused: { (): boolean; (): boolean };

                                                        method id

                                                        id: { (expected: string): void; (expected: string): void };

                                                          method label

                                                          label: { (expected: string): void; (expected: string): void };

                                                            method parents

                                                            parents: { (expected: string): void; (expected: string): void };

                                                              method readonly

                                                              readonly: { (): boolean; (): boolean };

                                                                method role

                                                                role: { (expected: string): void; (expected: string): void };

                                                                  method selected

                                                                  selected: { (): boolean; (): boolean };

                                                                    method style

                                                                    style: {
                                                                    (expected: string, expectedAttributeValue?: string | number): void;
                                                                    (expected: string, expectedAttributeValue?: string | number): void;
                                                                    };

                                                                      method tabbable

                                                                      tabbable: { (): boolean; (): boolean };

                                                                        method tagName

                                                                        tagName: { (expected: string): void; (expected: string): void };

                                                                          method text

                                                                          text: { (expected: string): void; (expected: string): void };

                                                                            method title

                                                                            title: { (expected: string): void; (expected: string): void };

                                                                              method value

                                                                              value: { (expected: string): void; (expected: string): void };

                                                                                method visible

                                                                                visible: { (): boolean; (): boolean };

                                                                                  Package Files (6)

                                                                                  Dependencies (12)

                                                                                  Dev Dependencies (7)

                                                                                  Peer Dependencies (2)

                                                                                  Badge

                                                                                  To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                                                                                  You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@instructure/ui-test-utils.

                                                                                  • Markdown
                                                                                    [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/@instructure/ui-test-utils)
                                                                                  • HTML
                                                                                    <a href="https://www.jsdocs.io/package/@instructure/ui-test-utils"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>