|
| 1 | +-- ROBLOX upstream: https://github.com/testing-library/react-testing-library/blob/v12.1.5/types/index.d.ts |
| 2 | +local Packages = script.Parent.Parent |
| 3 | +local LuauPolyfill = require(Packages.LuauPolyfill) |
| 4 | +local Object = LuauPolyfill.Object |
| 5 | +type Array<T> = LuauPolyfill.Array<T> |
| 6 | +type Object = LuauPolyfill.Object |
| 7 | + |
| 8 | +type React_ReactElement = any |
| 9 | +type DocumentFragment = any |
| 10 | +type React_JSXElementConstructor<T> = any |
| 11 | + |
| 12 | +local exports = {} |
| 13 | + |
| 14 | +-- TypeScript Version: 3.8 |
| 15 | +local domModule = require(Packages.DomTestingLibrary) |
| 16 | +local queries = domModule.queries |
| 17 | +type typeofQueries = typeof(queries) |
| 18 | + |
| 19 | +-- ROBLOX deviation START: ReactDOM not available |
| 20 | +type Renderer = any |
| 21 | +-- ROBLOX deviation END |
| 22 | +local reactAct = require(script.Parent.jsHelpers["react-dom"]["test-utils"]).act |
| 23 | +Object.assign(exports, require(Packages.DomTestingLibrary)) |
| 24 | + |
| 25 | +export type within = domModule.within |
| 26 | +export type QueryByBoundAttribute<T = Instance> = domModule.QueryByBoundAttribute<T> |
| 27 | +export type AllByBoundAttribute<T = Instance> = domModule.AllByBoundAttribute<T> |
| 28 | +export type FindAllByBoundAttribute<T = Instance> = domModule.FindAllByBoundAttribute<T> |
| 29 | +export type GetByBoundAttribute<T = Instance> = domModule.GetByBoundAttribute<T> |
| 30 | +export type FindByBoundAttribute<T = Instance> = domModule.FindByBoundAttribute<T> |
| 31 | +export type QueryByText<T = Instance> = domModule.QueryByText<T> |
| 32 | +export type AllByText<T = Instance> = domModule.AllByText<T> |
| 33 | +export type FindAllByText<T = Instance> = domModule.FindAllByText<T> |
| 34 | +export type GetByText<T = Instance> = domModule.GetByText<T> |
| 35 | +export type FindByText<T = Instance> = domModule.FindByText<T> |
| 36 | +export type getByPlaceholderText<T = Instance> = domModule.getByPlaceholderText<T> |
| 37 | +export type getAllByPlaceholderText<T = Instance> = domModule.getAllByPlaceholderText<T> |
| 38 | +export type queryByPlaceholderText<T = Instance> = domModule.queryByPlaceholderText<T> |
| 39 | +export type queryAllByPlaceholderText<T = Instance> = domModule.queryAllByPlaceholderText<T> |
| 40 | +export type findByPlaceholderText<T = Instance> = domModule.findByPlaceholderText<T> |
| 41 | +export type findAllByPlaceholderText<T = Instance> = domModule.findAllByPlaceholderText<T> |
| 42 | +export type getByText<T = Instance> = domModule.getByText<T> |
| 43 | +export type getAllByText<T = Instance> = domModule.getAllByText<T> |
| 44 | +export type queryByText<T = Instance> = domModule.queryByText<T> |
| 45 | +export type queryAllByText<T = Instance> = domModule.queryAllByText<T> |
| 46 | +export type findByText<T = Instance> = domModule.findByText<T> |
| 47 | +export type findAllByText<T = Instance> = domModule.findAllByText<T> |
| 48 | +export type getByDisplayValue<T = Instance> = domModule.getByDisplayValue<T> |
| 49 | +export type getAllByDisplayValue<T = Instance> = domModule.getAllByDisplayValue<T> |
| 50 | +export type queryByDisplayValue<T = Instance> = domModule.queryByDisplayValue<T> |
| 51 | +export type queryAllByDisplayValue<T = Instance> = domModule.queryAllByDisplayValue<T> |
| 52 | +export type findByDisplayValue<T = Instance> = domModule.findByDisplayValue<T> |
| 53 | +export type findAllByDisplayValue<T = Instance> = domModule.findAllByDisplayValue<T> |
| 54 | +export type getByTestId<T = Instance> = domModule.getByTestId<T> |
| 55 | +export type getAllByTestId<T = Instance> = domModule.getAllByTestId<T> |
| 56 | +export type queryByTestId<T = Instance> = domModule.queryByTestId<T> |
| 57 | +export type queryAllByTestId<T = Instance> = domModule.queryAllByTestId<T> |
| 58 | +export type findByTestId<T = Instance> = domModule.findByTestId<T> |
| 59 | +export type findAllByTestId<T = Instance> = domModule.findAllByTestId<T> |
| 60 | +export type WithSuggest = domModule.WithSuggest |
| 61 | +export type GetErrorFunction<Argument = any> = domModule.GetErrorFunction<Argument> |
| 62 | +export type SelectorMatcherOptions = domModule.SelectorMatcherOptions |
| 63 | +export type QueryByAttribute = domModule.QueryByAttribute |
| 64 | +export type AllByAttribute = domModule.AllByAttribute |
| 65 | +export type queryByAttribute = domModule.queryByAttribute |
| 66 | +export type queryAllByAttribute = domModule.queryAllByAttribute |
| 67 | +export type getElementError = domModule.getElementError |
| 68 | +export type QueryMethod<Argument, Return> = domModule.QueryMethod<Argument, Return> |
| 69 | +export type QueryBy<Argument> = domModule.QueryBy<Argument> |
| 70 | +export type GetAllBy<Argument> = domModule.GetAllBy<Argument> |
| 71 | +export type FindAllBy<Argument> = domModule.FindAllBy<Argument> |
| 72 | +export type GetBy<Argument> = domModule.GetBy<Argument> |
| 73 | +export type FindBy<Argument> = domModule.FindBy<Argument> |
| 74 | +export type BuiltQueryMethods<Argument> = domModule.BuiltQueryMethods<Argument> |
| 75 | +export type buildQueries<Argument> = domModule.buildQueries<Argument> |
| 76 | +export type Screen<Q> = domModule.Screen<Q> |
| 77 | +export type screen = domModule.screen |
| 78 | +export type waitForOptions = domModule.waitForOptions |
| 79 | +export type waitFor = domModule.waitFor |
| 80 | +export type waitForElementToBeRemoved<T> = domModule.waitForElementToBeRemoved<T> |
| 81 | +export type MatcherFunction = domModule.MatcherFunction |
| 82 | +export type Matcher = domModule.Matcher |
| 83 | +export type ByRoleMatcher = domModule.ByRoleMatcher |
| 84 | +export type NormalizerFn = domModule.NormalizerFn |
| 85 | +export type NormalizerOptions = domModule.NormalizerOptions |
| 86 | +export type MatcherOptions = domModule.MatcherOptions |
| 87 | +export type Match = domModule.Match |
| 88 | +export type DefaultNormalizerOptions = domModule.DefaultNormalizerOptions |
| 89 | +export type getDefaultNormalizer = domModule.getDefaultNormalizer |
| 90 | +export type getNodeText = domModule.getNodeText |
| 91 | +export type EventType = domModule.EventType |
| 92 | +export type FireFunction = domModule.FireFunction |
| 93 | +export type FireObject = domModule.FireObject |
| 94 | +export type CreateFunction = domModule.CreateFunction |
| 95 | +export type CreateObject = domModule.CreateObject |
| 96 | +export type createEvent = domModule.createEvent |
| 97 | +export type fireEvent = domModule.fireEvent |
| 98 | +export type BoundFunction<T> = domModule.BoundFunction<T> |
| 99 | +export type BoundFunctions<Q> = domModule.BoundFunctions<Q> |
| 100 | +export type Query = domModule.Query |
| 101 | +export type Queries = domModule.Queries |
| 102 | +export type getQueriesForElement = domModule.getQueriesForElement |
| 103 | +export type PrettyDOMOptions = domModule.PrettyDOMOptions |
| 104 | +export type prettyDOM = domModule.prettyDOM |
| 105 | +export type logDOM = domModule.logDOM |
| 106 | +export type prettyFormat_Colors = domModule.prettyFormat_Colors |
| 107 | +export type prettyFormat_CompareKeys = domModule.prettyFormat_CompareKeys |
| 108 | +export type prettyFormat_Options = domModule.prettyFormat_Options |
| 109 | +export type prettyFormat_OptionsReceived = domModule.prettyFormat_OptionsReceived |
| 110 | +export type prettyFormat_OldPlugin = domModule.prettyFormat_OldPlugin |
| 111 | +export type prettyFormat_NewPlugin = domModule.prettyFormat_NewPlugin |
| 112 | +export type prettyFormat_Plugin = domModule.prettyFormat_Plugin |
| 113 | +export type prettyFormat_Plugins = domModule.prettyFormat_Plugins |
| 114 | +export type prettyFormat_PrettyFormatOptions = domModule.prettyFormat_PrettyFormatOptions |
| 115 | +export type prettyFormat_Printer = domModule.prettyFormat_Printer |
| 116 | +export type prettyFormat_Refs = domModule.prettyFormat_Refs |
| 117 | +export type prettyFormat_Theme = domModule.prettyFormat_Theme |
| 118 | +export type Config = domModule.Config |
| 119 | +export type ConfigFn = domModule.ConfigFn |
| 120 | +export type configure = domModule.configure |
| 121 | +export type getConfig = domModule.getConfig |
| 122 | +export type QueryOptions = domModule.QueryOptions |
| 123 | +export type QueryArgs = domModule.QueryArgs |
| 124 | +export type Suggestion = domModule.Suggestion |
| 125 | +export type Variant = domModule.Variant |
| 126 | +export type Method = domModule.Method |
| 127 | +export type getSuggestedQuery = domModule.getSuggestedQuery |
| 128 | + |
| 129 | +export type RenderResult<Q = typeofQueries, Container = Instance, BaseElement = Container> = { |
| 130 | + container: Container, |
| 131 | + baseElement: BaseElement, |
| 132 | + debug_: ( |
| 133 | + baseElement: (Instance | Array<Instance>)?, |
| 134 | + maxLength: number?, |
| 135 | + options: prettyFormat_OptionsReceived? |
| 136 | + ) -> (), |
| 137 | + rerender: (ui: React_ReactElement) -> (), |
| 138 | + unmount: () -> (), |
| 139 | + asFragment: () -> DocumentFragment, |
| 140 | +} & Object --[[ ROBLOX TODO: Unhandled node for type: TSMappedType ]] --[[ { [P in keyof Q]: BoundFunction<Q[P]> } ]] |
| 141 | + |
| 142 | +export type RenderOptions<Q = typeofQueries, Container = Instance, BaseElement = Container> = { |
| 143 | + --[[ * |
| 144 | + * By default, React Testing Library will create a div and append that div to the document.body. Your React component will be rendered in the created div. If you provide your own HTMLElement container via this option, |
| 145 | + * it will not be appended to the document.body automatically. |
| 146 | + * |
| 147 | + * For example: If you are unit testing a `<tbody>` element, it cannot be a child of a div. In this case, you can |
| 148 | + * specify a table as the render container. |
| 149 | + * |
| 150 | + * @see https://testing-library.com/docs/react-testing-library/api/#container |
| 151 | + ]] |
| 152 | + container: Container?, |
| 153 | + --[[ * |
| 154 | + * Defaults to the container if the container is specified. Otherwise `document.body` is used for the default. This is used as |
| 155 | + * the base element for the queries as well as what is printed when you use `debug()`. |
| 156 | + * |
| 157 | + * @see https://testing-library.com/docs/react-testing-library/api/#baseelement |
| 158 | + ]] |
| 159 | + baseElement: BaseElement?, |
| 160 | + --[[ * |
| 161 | + * If `hydrate` is set to `true`, then it will render with `ReactDOM.hydrate`. This may be useful if you are using server-side |
| 162 | + * rendering and use ReactDOM.hydrate to mount your components. |
| 163 | + * |
| 164 | + * @see https://testing-library.com/docs/react-testing-library/api/#hydrate) |
| 165 | + ]] |
| 166 | + hydrate: boolean?, |
| 167 | + --[[ * |
| 168 | + * Queries to bind. Overrides the default set from DOM Testing Library unless merged. |
| 169 | + * |
| 170 | + * @see https://testing-library.com/docs/react-testing-library/api/#queries |
| 171 | + ]] |
| 172 | + queries: Q?, |
| 173 | + --[[ * |
| 174 | + * Pass a React Component as the wrapper option to have it rendered around the inner element. This is most useful for creating |
| 175 | + * reusable custom render functions for common data providers. See setup for examples. |
| 176 | + * |
| 177 | + * @see https://testing-library.com/docs/react-testing-library/api/#wrapper |
| 178 | + ]] |
| 179 | + wrapper: React_JSXElementConstructor<{ children: React_ReactElement }>?, |
| 180 | +} |
| 181 | +-- ROBLOX deviation START: can't express equivalent, we just return same type |
| 182 | +-- type Omit<T, K> = Pick<T, Exclude<any --[[ ROBLOX TODO: Unhandled node for type: TSTypeOperator ]] --[[ keyof T ]], K>> |
| 183 | +type Omit<T, K> = T |
| 184 | +-- ROBLOX deviation END |
| 185 | + |
| 186 | +--[[ * |
| 187 | + * Render into a container which is appended to document.body. It should be used with cleanup. |
| 188 | +]] |
| 189 | +export type render<Q = typeofQueries, Container = Instance, BaseElement = Container> = |
| 190 | + (( |
| 191 | + ui: React_ReactElement, |
| 192 | + options: RenderOptions<Q, Container, BaseElement> |
| 193 | + ) -> RenderResult<Q, Container, BaseElement>) |
| 194 | + | ((ui: React_ReactElement, options: Omit<RenderOptions, "queries">?) -> RenderResult) |
| 195 | + |
| 196 | +--[[* |
| 197 | + * Unmounts React trees that were mounted with render. |
| 198 | +]] |
| 199 | +export type cleanup = () -> () |
| 200 | + |
| 201 | +--[[ * |
| 202 | + * Simply calls ReactDOMTestUtils.act(cb) |
| 203 | + * If that's not available (older version of react) then it |
| 204 | + * simply calls the given callback immediately |
| 205 | +]] |
| 206 | +-- ROBLOX deviation START: dropped support for oder versions |
| 207 | +export type act = typeof(reactAct) |
| 208 | +-- ROBLOX deviation END |
| 209 | +return exports |
0 commit comments