Skip to content

Commit 2cf1b64

Browse files
committed
update tests
1 parent 8632e84 commit 2cf1b64

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

test/basic.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -716,8 +716,8 @@ test('maybeSingle w/ throwOnError', async () => {
716716
.from('messages')
717717
.select()
718718
.eq('message', 'i do not exist')
719-
.throwOnError()
720719
.maybeSingle()
720+
.throwOnError()
721721
.then(undefined, () => {
722722
passes = false
723723
})

test/index.test-d.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,22 @@ const postgrest = new PostgrestClient<Database>(REST_URL)
9898
expectType<PostgrestSingleResponse<SelectQueryError<`Referencing missing column \`dat\``>[]>>(res)
9999
}
100100

101-
// throw on error
101+
// throw on error on query
102102
{
103-
const { data } = await postgrest
104-
.from('users')
105-
.select('*')
106-
.returns<{ a: string; b: number }[]>()
107-
.throwOnError()
103+
const { data } = await postgrest.from('users').select('username').throwOnError()
104+
expectType<{ username: string }[]>(data)
105+
}
106+
107+
// queries without throw on error have nullable results
108+
{
109+
const { data } = await postgrest.from('users').select('username')
110+
expectType<{ username: string }[] | null>(data)
111+
}
112+
113+
// throw on error on client
114+
{
115+
const strictClient = postgrest.throwOnError()
108116

109-
expectType<{ a: string; b: number }>(data[0])
117+
const { data } = await strictClient.from('users').select('username')
118+
expectType<{ username: string }[]>(data)
110119
}

0 commit comments

Comments
 (0)