|
3 | 3 | import {EventEmitter} from 'node:events'
|
4 | 4 | import {scheduler} from 'node:timers/promises'
|
5 | 5 | import {test, expect} from '@jest/globals'
|
6 |
| -import {renderHookToSnapshotStream} from '@testing-library/react-render-stream' |
| 6 | +import { |
| 7 | + renderHookToSnapshotStream, |
| 8 | + SnapshotStream, |
| 9 | +} from '@testing-library/react-render-stream' |
7 | 10 | import * as React from 'react'
|
8 | 11 |
|
9 | 12 | const testEvents = new EventEmitter<{
|
@@ -72,3 +75,48 @@ test.each<[type: string, initialValue: unknown, ...nextValues: unknown[]]>([
|
72 | 75 | expect(await takeSnapshot()).toBe(nextValue)
|
73 | 76 | }
|
74 | 77 | })
|
| 78 | + |
| 79 | +test.skip('type test: render function without an argument -> no argument required for `rerender`', async () => { |
| 80 | + { |
| 81 | + // prop type has nothing to infer on - defaults to `void` |
| 82 | + const stream = await renderHookToSnapshotStream(() => {}) |
| 83 | + const _test1: SnapshotStream<void, void> = stream |
| 84 | + // @ts-expect-error should not be assignable |
| 85 | + const _test2: SnapshotStream<void, string> = stream |
| 86 | + await stream.rerender() |
| 87 | + // @ts-expect-error invalid argument |
| 88 | + await stream.rerender('foo') |
| 89 | + } |
| 90 | + { |
| 91 | + // prop type is implicitly set via the render function argument |
| 92 | + const stream = await renderHookToSnapshotStream((_arg1: string) => {}) |
| 93 | + // @ts-expect-error should not be assignable |
| 94 | + const _test1: SnapshotStream<void, void> = stream |
| 95 | + const _test2: SnapshotStream<void, string> = stream |
| 96 | + // @ts-expect-error missing argument |
| 97 | + await stream.rerender() |
| 98 | + await stream.rerender('foo') |
| 99 | + } |
| 100 | + { |
| 101 | + // prop type is implicitly set via the initialProps argument |
| 102 | + const stream = await renderHookToSnapshotStream(() => {}, { |
| 103 | + initialProps: 'initial', |
| 104 | + }) |
| 105 | + // @ts-expect-error should not be assignable |
| 106 | + const _test1: SnapshotStream<void, void> = stream |
| 107 | + const _test2: SnapshotStream<void, string> = stream |
| 108 | + // @ts-expect-error missing argument |
| 109 | + await stream.rerender() |
| 110 | + await stream.rerender('foo') |
| 111 | + } |
| 112 | + { |
| 113 | + // argument is optional |
| 114 | + const stream = await renderHookToSnapshotStream((_arg1?: string) => {}) |
| 115 | + |
| 116 | + const _test1: SnapshotStream<void, void> = stream |
| 117 | + const _test2: SnapshotStream<void, string> = stream |
| 118 | + const _test3: SnapshotStream<void, string | undefined> = stream |
| 119 | + await stream.rerender() |
| 120 | + await stream.rerender('foo') |
| 121 | + } |
| 122 | +}) |
0 commit comments