Skip to content

Commit

Permalink
minor fixup, tests
Browse files Browse the repository at this point in the history
  • Loading branch information
phryneas committed Oct 11, 2024
1 parent 5bafa3c commit e5645c0
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 2 deletions.
31 changes: 31 additions & 0 deletions src/__tests__/renderToRenderStream.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,37 @@ describe('snapshotDOM', () => {
expect(input.value).toBe('2')
}
})

test('queries option', async () => {
function Component() {
return null
}
const queries = {
foo: (_: any) => {
return null
},
}
const {takeRender, renderResultPromise} = renderToRenderStream(
<Component />,
{
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
26 changes: 26 additions & 0 deletions src/renderStream/__tests__/createRenderStream.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,32 @@ describe('snapshotDOM', () => {
}
}
})

test('queries option', async () => {
function Component() {
return null
}
const queries = {
foo: (_: any) => {
return null
},
}

const {takeRender, render} = createRenderStream({
snapshotDOM: true,
queries,
})
render(<Component />)

const {withinDOM} = await takeRender()
expect(withinDOM().foo()).toBe(null)
function _typeTest() {
// @ts-expect-error should not be present
withinDOM().getByText
withinDOM().debug()
const _str: string = withinDOM().logTestingPlaygroundURL()
}
})
})

describe('replaceSnapshot', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/renderStream/syncQueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export type SyncQueries = {
: K]: OriginalQueries[K]
}

export const syncQueries = Object.values(
export const syncQueries = Object.fromEntries(
Object.entries(queries).filter(
([key]) => key.startsWith('get') || key.startsWith('find'),
),
Expand Down
2 changes: 1 addition & 1 deletion src/renderToRenderStream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {SyncQueries} from './renderStream/syncQueries.js'
type RenderOptions<
Snapshot extends ValidSnapshot = void,
Q extends Queries = SyncQueries,
> = BaseOptions<Q> & RenderStreamOptions<Snapshot>
> = BaseOptions<Q> & RenderStreamOptions<Snapshot, Q>

export interface RenderStreamWithRenderResult<
Snapshot extends ValidSnapshot = void,
Expand Down

0 comments on commit e5645c0

Please sign in to comment.