-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* ESM tests * fix snapshot file paths * update snapshot * Configure react testing library to always use strict mode. Use individual `configure` calls to specify otherwise. * lint
- Loading branch information
Showing
131 changed files
with
2,929 additions
and
3,005 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Bentley Systems, Incorporated. All rights reserved. | ||
* See LICENSE.md in the project root for license terms and full copyright notice. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import { createElement, PropsWithChildren, ReactElement } from "react"; | ||
import { ThemeProvider } from "@itwin/itwinui-react"; | ||
import { RenderOptions, RenderResult, render as renderRTL } from "@testing-library/react"; | ||
import { userEvent, UserEvent } from "@testing-library/user-event"; | ||
|
||
function createWrapper(Outer: React.JSXElementConstructor<{ children: React.ReactNode }>) { | ||
return (Inner?: React.JSXElementConstructor<{ children: React.ReactNode }>) => { | ||
return Inner ? ({ children }: PropsWithChildren<unknown>) => createElement(Outer, undefined, createElement(Inner, undefined, children)) : Outer; | ||
}; | ||
} | ||
|
||
function combineWrappers(wraps: Array<ReturnType<typeof createWrapper>>, wrapper?: React.JSXElementConstructor<{ children: React.ReactNode }>) { | ||
let currWrapper = wrapper; | ||
for (const wrap of wraps) { | ||
currWrapper = wrap(currWrapper); | ||
} | ||
return currWrapper; | ||
} | ||
|
||
function createDefaultWrappers(addThemeProvider?: boolean) { | ||
const wrappers: Array<ReturnType<typeof createWrapper>> = []; | ||
if (addThemeProvider) { | ||
wrappers.push(createWrapper(ThemeProvider)); | ||
} | ||
return wrappers; | ||
} | ||
|
||
/** | ||
* Custom render function that wraps around `render` function from `@testing-library/react` and additionally | ||
* setup `userEvent` from `@testing-library/user-event`. | ||
* | ||
* It should be used when test need to do interactions with rendered components. | ||
*/ | ||
function customRender(ui: ReactElement, options?: RenderOptions & { addThemeProvider?: boolean }): RenderResult & { user: UserEvent } { | ||
const wrappers = createDefaultWrappers(options?.addThemeProvider); | ||
const wrapper = combineWrappers(wrappers, options?.wrapper); | ||
return { | ||
...renderRTL(ui, { ...options, wrapper }), | ||
user: userEvent.setup(), | ||
}; | ||
} | ||
|
||
export * from "@testing-library/react"; | ||
export { customRender as render }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.