Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,38 @@ describe('injectQuery', () => {
expect(rendered.getByText('data: test')).toBeInTheDocument()
})

it('should show placeholderData until queryFn resolves and then expose real data', async () => {
const key = queryKey()

@Component({
template: `
<div>data: {{ query.data() }}</div>
<div>isPlaceholderData: {{ query.isPlaceholderData() }}</div>
<div>isSuccess: {{ query.isSuccess() }}</div>
`,
})
class Page {
readonly query = injectQuery(() => ({
queryKey: key,
queryFn: () => sleep(10).then(() => 'real-data'),
placeholderData: 'placeholder',
}))
}

const rendered = await render(Page)

expect(rendered.getByText('data: placeholder')).toBeInTheDocument()
expect(rendered.getByText('isPlaceholderData: true')).toBeInTheDocument()
expect(rendered.getByText('isSuccess: true')).toBeInTheDocument()

await vi.advanceTimersByTimeAsync(11)
rendered.fixture.detectChanges()

expect(rendered.getByText('data: real-data')).toBeInTheDocument()
expect(rendered.getByText('isPlaceholderData: false')).toBeInTheDocument()
expect(rendered.getByText('isSuccess: true')).toBeInTheDocument()
})

it('should update query on options contained signal change', async () => {
const key1 = queryKey()
const key2 = queryKey()
Expand Down
Loading