UNPKG

orphic-cypress

Version:

Set of utilities and typescript transformers to cover storybook stories with cypress component tests

65 lines (64 loc) 2.44 kB
import React from "react"; import type { WithCy } from "../types"; /** Props for the UnitTest component, mostly to link to story */ export type UnitTestProps = { /** name matching the story's name */ name?: string; /** id matching the story's name. either name or id must be provided */ id?: string; /** * description for tests which have cy function or cyTest formats. * Provides a reasonable default but can opt out with `false` */ description?: string | false | null; /** * Parameters, probably passed in from parent in unitTestDecorator, * though I suppose passing in directly could be useful somehow */ parameters?: WithCy<any>; /** * Potentially internal only: if the literate test is from code block. Used to * deduplicate display of code block in docs view */ isCodeBlock?: boolean; }; /** Context for parameters used in unitTestDecorator */ export declare const ParametersContext: React.Context<{}>; /** * Display test information for pure unit test stories. * This is likey used in mdx files and must have a 'name' or 'id' which would appropriately * match to the proper story. * See [the task story](https://quotapath.github.io/orphic-cypress/storybook/?path=/docs/cypressutils-tasks--arbitrary-task#literate-testing) * for detailed use. * ```ts * <Story * name="ArbitraryTask" * parameters={{ * cy: () => * cy.arbitraryTask(2).then(($num) => expect($num).to.equal(2)), * }} * > * <UnitTest name="ArbitraryTask" /> * </Story> * ``` * * Or by providing the `unitTestDecorator` decorator and setting a `cyUnitTest` * parameter to `true` */ export declare const UnitTest: (props: UnitTestProps) => JSX.Element | null; /** * Gets the code block matching a story from the mdx page. * Just a tad hacky with how its getting to the MDXContent * @private */ export declare const getStoryCyFromMdxCodeBlock: (parameters: any, storyName: string, functionize?: boolean) => { [description: string]: string; }; /** * A storybook decorator that provides a parameter context for the sake * of showing UnitTest components in cypress and storybook canvas as opposed * to just docs, and allows display without manually adding a UnitTest component * via `cyUnitTest` parameter. * TODO: types would be nice, but have been annoying */ export declare const unitTestDecorator: (Story: any, context: any) => JSX.Element;