Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: testing-library/react-testing-library
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v16.0.0
Choose a base ref
...
head repository: testing-library/react-testing-library
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v16.0.1
Choose a head ref
  • 2 commits
  • 4 files changed
  • 1 contributor

Commits on Aug 28, 2024

  1. Fix React Canary and Experimental tests (#1353)

    eps1lon authored Aug 28, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    7a28fa9 View commit details

Commits on Aug 29, 2024

  1. fix: Add support for exactOptionalPropertyTypes in TypeScript (#1351)

    eps1lon authored Aug 29, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    3dcd8a9 View commit details
Showing with 24 additions and 13 deletions.
  1. +4 −0 tests/setup-env.js
  2. +13 −12 types/index.d.ts
  3. +6 −1 types/test.tsx
  4. +1 −0 types/tsconfig.json
4 changes: 4 additions & 0 deletions tests/setup-env.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import '@testing-library/jest-dom/extend-expect'
import './failOnUnexpectedConsoleCalls'
import {TextEncoder} from 'util'
import {MessageChannel} from 'worker_threads'

global.TextEncoder = TextEncoder
// TODO: Revisit once https://github.com/jsdom/jsdom/issues/2448 is resolved
// This isn't perfect but good enough.
global.MessageChannel = MessageChannel
25 changes: 13 additions & 12 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -36,9 +36,10 @@ export type RenderResult<
baseElement?:
| RendererableContainer
| HydrateableContainer
| Array<RendererableContainer | HydrateableContainer>,
maxLength?: number,
options?: prettyFormat.OptionsReceived,
| Array<RendererableContainer | HydrateableContainer>
| undefined,
maxLength?: number | undefined,
options?: prettyFormat.OptionsReceived | undefined,
) => void
rerender: (ui: React.ReactNode) => void
unmount: () => void
@@ -97,40 +98,40 @@ export interface RenderOptions<
*
* @see https://testing-library.com/docs/react-testing-library/api/#container
*/
container?: Container
container?: Container | undefined
/**
* Defaults to the container if the container is specified. Otherwise `document.body` is used for the default. This is used as
* the base element for the queries as well as what is printed when you use `debug()`.
*
* @see https://testing-library.com/docs/react-testing-library/api/#baseelement
*/
baseElement?: BaseElement
baseElement?: BaseElement | undefined
/**
* If `hydrate` is set to `true`, then it will render with `ReactDOM.hydrate`. This may be useful if you are using server-side
* rendering and use ReactDOM.hydrate to mount your components.
*
* @see https://testing-library.com/docs/react-testing-library/api/#hydrate)
*/
hydrate?: boolean
hydrate?: boolean | undefined
/**
* Only works if used with React 18.
* Set to `true` if you want to force synchronous `ReactDOM.render`.
* Otherwise `render` will default to concurrent React if available.
*/
legacyRoot?: boolean
legacyRoot?: boolean | undefined
/**
* Queries to bind. Overrides the default set from DOM Testing Library unless merged.
*
* @see https://testing-library.com/docs/react-testing-library/api/#queries
*/
queries?: Q
queries?: Q | undefined
/**
* Pass a React Component as the wrapper option to have it rendered around the inner element. This is most useful for creating
* reusable custom render functions for common data providers. See setup for examples.
*
* @see https://testing-library.com/docs/react-testing-library/api/#wrapper
*/
wrapper?: React.JSXElementConstructor<{children: React.ReactNode}>
wrapper?: React.JSXElementConstructor<{children: React.ReactNode}> | undefined
}

type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>
@@ -148,7 +149,7 @@ export function render<
): RenderResult<Q, Container, BaseElement>
export function render(
ui: React.ReactNode,
options?: Omit<RenderOptions, 'queries'>,
options?: Omit<RenderOptions, 'queries'> | undefined,
): RenderResult

export interface RenderHookResult<Result, Props> {
@@ -223,7 +224,7 @@ export interface RenderHookOptions<
* The argument passed to the renderHook callback. Can be useful if you plan
* to use the rerender utility to change the values passed to your hook.
*/
initialProps?: Props
initialProps?: Props | undefined
}

/**
@@ -238,7 +239,7 @@ export function renderHook<
BaseElement extends RendererableContainer | HydrateableContainer = Container,
>(
render: (initialProps: Props) => Result,
options?: RenderHookOptions<Props, Q, Container, BaseElement>,
options?: RenderHookOptions<Props, Q, Container, BaseElement> | undefined,
): RenderHookResult<Result, Props>

/**
7 changes: 6 additions & 1 deletion types/test.tsx
Original file line number Diff line number Diff line change
@@ -132,7 +132,12 @@ export function wrappedRender(
return <div>{children}</div>
}

return pure.render(ui, {wrapper: Wrapper, ...options})
return pure.render(ui, {
wrapper: Wrapper,
// testing exactOptionalPropertyTypes comaptibility
hydrate: options?.hydrate,
...options,
})
}

export function wrappedRenderB(
1 change: 1 addition & 0 deletions types/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"extends": "../node_modules/kcd-scripts/shared-tsconfig.json",
"compilerOptions": {
"exactOptionalPropertyTypes": true,
"skipLibCheck": false
},
"include": ["."]