-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
test.ts
65 lines (57 loc) · 1.82 KB
/
test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { getTestClient } from '../../../../utils/getTestClient'
describe('prisma promises', () => {
/**
* Requests must get sent if we call `.catch`
*/
test('catch', async () => {
const PrismaClient = await getTestClient()
const prisma = new PrismaClient()
const handler = (e) => Promise.reject(e)
const remove = await prisma.user.deleteMany().catch(handler)
const queryRaw = await prisma.$queryRawUnsafe('SELECT 1').catch(handler)
const executeRaw = await prisma.$executeRawUnsafe('DELETE FROM User').catch(handler)
const findMany = await prisma.user.findMany().catch(handler)
expect(remove).toMatchInlineSnapshot(`
Object {
count: 0,
}
`)
expect(queryRaw).toMatchInlineSnapshot(`
Array [
Object {
1: 1n,
},
]
`)
expect(executeRaw).toMatchInlineSnapshot(`0`)
expect(findMany).toMatchInlineSnapshot(`Array []`)
await prisma.$disconnect()
})
/**
* Requests must get sent if we call `.finally`
*/
test('finally', async () => {
const PrismaClient = await getTestClient()
const prisma = new PrismaClient()
const handler = () => {}
const remove = await prisma.user.deleteMany().finally(handler)
const queryRaw = await prisma.$queryRawUnsafe('SELECT 1').finally(handler)
const executeRaw = await prisma.$executeRawUnsafe('DELETE FROM User').finally(handler)
const findMany = await prisma.user.findMany().finally(handler)
expect(remove).toMatchInlineSnapshot(`
Object {
count: 0,
}
`)
expect(queryRaw).toMatchInlineSnapshot(`
Array [
Object {
1: 1n,
},
]
`)
expect(executeRaw).toMatchInlineSnapshot(`0`)
expect(findMany).toMatchInlineSnapshot(`Array []`)
await prisma.$disconnect()
})
})