-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathor.predicate.test.ts
More file actions
executable file
·71 lines (62 loc) · 1.79 KB
/
or.predicate.test.ts
File metadata and controls
executable file
·71 lines (62 loc) · 1.79 KB
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
66
67
68
69
70
71
import { expect } from 'vitest'
import type { HookContext } from '@feathersjs/feathers'
import { or as some } from './or.predicate.js'
import { or, some as someAlias } from '../index.js'
describe('predicates/or', () => {
it('is exported as "some" alias', () => {
expect(someAlias).toBe(or)
})
it('returns true synchronously when empty', () => {
expect(some()({} as HookContext)).toBe(true)
})
it('returns true when all are undefined', () => {
expect(some(undefined, undefined, undefined)({} as HookContext)).toBe(true)
})
it('returns true synchronously when at least 1 hook is true', () => {
expect(
some(
() => false,
() => false,
() => Promise.resolve(false),
() => Promise.resolve(true),
() => true,
)({} as HookContext),
).toBe(true)
})
it('returns true when at least 1 async hook is true', async () => {
await expect(
some(
() => false,
() => Promise.resolve(false),
() => Promise.resolve(true),
)({} as HookContext),
).resolves.toBe(true)
})
it('rejects with the error', async () => {
await expect(
async () =>
await some(() => Promise.reject(new Error('errored')))(
{} as HookContext,
),
).rejects.toThrow('errored')
})
it('does not run all predicates when one is true', () => {
const fn = vi.fn(() => {
return true
})
expect(some(fn, fn, fn)({} as HookContext)).toBe(true)
expect(fn).toHaveBeenCalledTimes(1)
})
it('when all hooks are falsey', async () => {
await expect(
some(
() => false,
() => Promise.resolve(false),
// @ts-expect-error test case
() => null,
() => undefined,
() => 0,
)({} as HookContext),
).resolves.toBe(false)
})
})