From 04c222de7679c2d55e7ca4bce474b7cae1e3aa9c Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Tue, 3 Dec 2024 09:56:31 +0100 Subject: [PATCH] remove `renderToRenderStream` --- README.md | 22 ----- src/__tests__/renderToRenderStream.test.tsx | 94 --------------------- src/pure.ts | 2 - src/renderToRenderStream.ts | 55 ------------ 4 files changed, 173 deletions(-) delete mode 100644 src/__tests__/renderToRenderStream.test.tsx delete mode 100644 src/renderToRenderStream.ts diff --git a/README.md b/README.md index 6b1383c2c..79c1164b2 100644 --- a/README.md +++ b/README.md @@ -58,28 +58,6 @@ test('iterate through renders with DOM snapshots', async () => { }) ``` -### `renderToRenderStream` as a shortcut for `createRenderStream` and calling `render` - -In every place you would call - -```js -const {takeRender, render} = createRenderStream(options) -const utils = await render(, options) -``` - -you can also call - -```js -const renderStream = renderToRenderStream(, combinedOptions) -// if required -const utils = await renderStream.renderResultPromise -``` - -This might be shorter (especially in cases where you don't need to access -`utils`), but keep in mind that the render is executed **asynchronously** after -calling `renderToRenderStream`, and that you need to `await renderResultPromise` -if you need access to `utils` as returned by `render`. - ### `renderHookToSnapshotStream` Usage is very similar to RTL's `renderHook`, but you get a `snapshotStream` diff --git a/src/__tests__/renderToRenderStream.test.tsx b/src/__tests__/renderToRenderStream.test.tsx deleted file mode 100644 index 195ed6ad4..000000000 --- a/src/__tests__/renderToRenderStream.test.tsx +++ /dev/null @@ -1,94 +0,0 @@ -/* eslint-disable @typescript-eslint/no-use-before-define */ -import {describe, test, expect} from '@jest/globals' -import {renderToRenderStream} from '@testing-library/react-render-stream' -import {userEvent} from '@testing-library/user-event' -import * as React from 'react' -function CounterForm({ - value, - onIncrement, -}: { - value: number - onIncrement: () => void -}) { - return ( -
- - -
- ) -} - -describe('snapshotDOM', () => { - test('basic functionality', async () => { - function Counter() { - const [value, setValue] = React.useState(0) - return ( - setValue(v => v + 1)} /> - ) - } - - const {takeRender, renderResultPromise} = renderToRenderStream( - , - { - snapshotDOM: true, - }, - ) - const utils = await renderResultPromise - const incrementButton = utils.getByText('Increment') - await userEvent.click(incrementButton) - await userEvent.click(incrementButton) - { - const {withinDOM} = await takeRender() - const input = withinDOM().getByLabelText('Value') - expect(input.value).toBe('0') - } - { - const {withinDOM} = await takeRender() - const input = withinDOM().getByLabelText('Value') - expect(input.value).toBe('1') - } - { - const {withinDOM} = await takeRender() - const input = withinDOM().getByLabelText('Value') - expect(input.value).toBe('2') - } - }) - - test('queries option', async () => { - function Component() { - return null - } - const queries = { - foo: (_: any) => { - return null - }, - } - const {takeRender, renderResultPromise} = renderToRenderStream( - , - { - queries, - snapshotDOM: true, - }, - ) - const utils = await renderResultPromise - expect(utils.foo()).toBe(null) - const {withinDOM} = await takeRender() - expect(withinDOM().foo()).toBe(null) - function _typeTest() { - // @ts-expect-error should not be present - utils.getByText - // @ts-expect-error should not be present - withinDOM().getByText - utils.debug() - withinDOM().debug() - const _str: string = withinDOM().logTestingPlaygroundURL() - } - }) -}) - -// for more tests, see the `createRenderStream` test suite, as `renderToRenderStream` is just a wrapper around that diff --git a/src/pure.ts b/src/pure.ts index fd6d7f010..7e1dce71f 100644 --- a/src/pure.ts +++ b/src/pure.ts @@ -12,8 +12,6 @@ export {useTrackRenders} from './renderStream/useTrackRenders.js' export type {SyncScreen} from './renderStream/Render.js' -export {renderToRenderStream} from './renderToRenderStream.js' -export type {RenderStreamWithRenderResult} from './renderToRenderStream.js' export {renderHookToSnapshotStream} from './renderHookToSnapshotStream.js' export type {SnapshotStream} from './renderHookToSnapshotStream.js' diff --git a/src/renderToRenderStream.ts b/src/renderToRenderStream.ts deleted file mode 100644 index afcf10386..000000000 --- a/src/renderToRenderStream.ts +++ /dev/null @@ -1,55 +0,0 @@ -import {type RenderOptions as BaseOptions} from '@testing-library/react/pure.js' -import {type Queries} from '@testing-library/dom' -import { - createRenderStream, - type RenderStreamOptions, - type RenderStream, - type ValidSnapshot, -} from './renderStream/createRenderStream.js' -import {SyncQueries} from './renderStream/syncQueries.js' -import {AsyncRenderResult} from './renderWithoutAct.js' - -type RenderOptions< - Snapshot extends ValidSnapshot = void, - Q extends Queries = SyncQueries, -> = BaseOptions & RenderStreamOptions - -export interface RenderStreamWithRenderResult< - Snapshot extends ValidSnapshot = void, - Q extends Queries = SyncQueries, -> extends RenderStream { - renderResultPromise: Promise> -} - -/** - * Render into a container which is appended to document.body. It should be used with cleanup. - */ -export function renderToRenderStream< - Snapshot extends ValidSnapshot = void, - Q extends Queries = SyncQueries, ->( - ui: React.ReactNode, - { - onRender, - snapshotDOM, - initialSnapshot, - skipNonTrackingRenders, - queries, - ...options - }: RenderOptions = {}, -): RenderStreamWithRenderResult { - const {render, ...stream} = createRenderStream({ - onRender, - snapshotDOM, - initialSnapshot, - skipNonTrackingRenders, - queries, - }) - // `render` needs to be called asynchronously here, because the definition of `ui` - // might contain components that reference the return value of `renderToRenderStream` - // itself, e.g. `replaceSnapshot` or `mergeSnapshot`. - const renderResultPromise = Promise.resolve().then(() => - render(ui, {...options, queries}), - ) - return {...stream, renderResultPromise} -}