-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMaybeResult.spec.ts
More file actions
59 lines (50 loc) · 1.4 KB
/
MaybeResult.spec.ts
File metadata and controls
59 lines (50 loc) · 1.4 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
import assert from 'assert'
import { describe, it } from 'node:test'
import type { MaybeResult } from './MaybeResult.ts'
import {
assertProblem,
assertResult,
isProblem,
isResult,
} from './MaybeResult.ts'
import { ProblemDetailError } from './ProblemDetail.ts'
const ok: MaybeResult<number> = { result: 42 }
const err: MaybeResult<number> = {
error: new ProblemDetailError({
type: 'https://example.com/error',
title: 'Error',
status: 400,
}),
}
void describe('isResult', () => {
void it('returns true for a Result', () => {
assert.strictEqual(isResult(ok), true)
})
void it('returns false for a ProblemResult', () => {
assert.strictEqual(isResult(err), false)
})
})
void describe('isProblem', () => {
void it('returns true for a ProblemResult', () => {
assert.strictEqual(isProblem(err), true)
})
void it('returns false for a Result', () => {
assert.strictEqual(isProblem(ok), false)
})
})
void describe('assertResult', () => {
void it('does not throw for a Result', () => {
assert.doesNotThrow(() => assertResult(ok))
})
void it('throws TypeError for a ProblemResult', () => {
assert.throws(() => assertResult(err), TypeError)
})
})
void describe('assertProblem', () => {
void it('does not throw for a ProblemResult', () => {
assert.doesNotThrow(() => assertProblem(err))
})
void it('throws TypeError for a Result', () => {
assert.throws(() => assertProblem(ok), TypeError)
})
})