forked from piotrwitek/typesafe-actions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.spec.ts
151 lines (136 loc) · 5.08 KB
/
action.spec.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import * as T from './type-helpers'; // type-tests global
import { action } from './action';
// @dts-jest:group with symbol
{
const ACTION = Symbol(1);
const withSymbol = () => action(ACTION as any);
// @dts-jest:pass:snap
withSymbol(); // => { type: ACTION }
}
// @dts-jest:group with type only
{
const withTypeOnly = () => action('ACTION');
// @dts-jest:pass:snap
withTypeOnly(); // => { type: 'ACTION' }
}
// @dts-jest:group with payload
{
const withPayload = (message: string) => action('ACTION', message);
// @dts-jest:pass:snap
withPayload('Hello!'); // => { type: 'ACTION',payload: 'Hello!' }
}
// @dts-jest:group with optional payload
{
const withOptionalPayload = (message?: string) => action('ACTION', message);
// @dts-jest:pass:snap
withOptionalPayload(); // => { type: 'ACTION' }
// @dts-jest:pass:snap
withOptionalPayload('Hello!'); // => { type: 'ACTION', payload: 'Hello!' }
}
// @dts-jest:group with meta
{
const withMeta = (scope: string) => action('ACTION', undefined, scope);
// @dts-jest:pass:snap
withMeta('info'); // => { type: 'ACTION', meta: 'info' }
}
// @dts-jest:group with optional meta
{
const withOptionalMeta = (scope?: string) =>
action('ACTION', undefined, scope);
// @dts-jest:pass:snap
withOptionalMeta(); // => { type: 'ACTION' }
// @dts-jest:pass:snap
withOptionalMeta('info'); // => { type: 'ACTION', meta: 'info' }
}
// @dts-jest:group with payload and meta
{
const withPayloadAndMeta = (message: string, scope: string) =>
action('ACTION', message, scope);
// @dts-jest:pass:snap
withPayloadAndMeta('Hello!', 'info'); // => { type: 'ACTION', payload: 'Hello!', meta: 'info' }
}
// @dts-jest:group with optional payload and meta
{
const withOptionalPayloadAndMeta = (scope: string, message?: string) =>
action('ACTION', message, scope);
// @dts-jest:pass:snap
withOptionalPayloadAndMeta('info'); // => { type: 'ACTION', meta: 'info' }
// @dts-jest:pass:snap
withOptionalPayloadAndMeta('info', 'Hello!'); // => { type: 'ACTION', payload: 'Hello!', meta: 'info' }
}
// @dts-jest:group with payload and optional meta
{
const withPayloadAndOptionalMeta = (message: string, scope?: string) =>
action('ACTION', message, scope);
// @dts-jest:pass:snap
withPayloadAndOptionalMeta('Hello!'); // => { type: 'ACTION', payload: 'Hello!' }
// @dts-jest:pass:snap
withPayloadAndOptionalMeta('Hello!', 'info'); // => { type: 'ACTION', payload: 'Hello!', meta: 'info' }
}
// @dts-jest:group with optional payload and optional meta
{
const withOptionalPayloadAndOptionalMeta = (
message?: string,
scope?: string
) => action('ACTION', message, scope);
// @dts-jest:pass:snap
withOptionalPayloadAndOptionalMeta(); // => { type: 'ACTION' }
// @dts-jest:pass:snap
withOptionalPayloadAndOptionalMeta('Hello!'); // => { type: 'ACTION', payload: 'Hello!' }
// @dts-jest:pass:snap
withOptionalPayloadAndOptionalMeta('Hello!', 'info'); // => { type: 'ACTION', payload: 'Hello!', meta: 'info' }
}
// @dts-jest:group with error
{
const withError = (error: boolean) =>
action('ACTION', undefined, undefined, error);
// @dts-jest:pass:snap
withError(true); // => { type: 'ACTION', error: true }
}
// @dts-jest:group with optional error
{
const withOptionalError = (error?: boolean) =>
action('ACTION', undefined, undefined, error);
// @dts-jest:pass:snap
withOptionalError(); // => { type: 'ACTION' }
// @dts-jest:pass:snap
withOptionalError(true); // => { type: 'ACTION', error: true }
}
// @dts-jest:group with payload, meta, and error
{
const withPayloadMetaAndError = (
message: string,
scope: string,
error: boolean
) => action('ACTION', message, scope, error);
// @dts-jest:pass:snap
withPayloadMetaAndError('Hello!', 'info', true); // => { type: 'ACTION', payload: 'Hello!', meta: 'info', error: true }
}
// @dts-jest:group with payload, meta, and optional error
{
const withPayloadMetaAndOptionalError = (
message: string,
scope: string,
error?: boolean
) => action('ACTION', message, scope, error);
// @dts-jest:pass:snap
withPayloadMetaAndOptionalError('Hello!', 'info'); // => { type: 'ACTION', payload: 'Hello!', meta: 'info' }
// @dts-jest:pass:snap
withPayloadMetaAndOptionalError('Hello!', 'info', true); // => { type: 'ACTION', payload: 'Hello!', meta: 'info', error: true }
}
// @dts-jest:group with optional payload, optional meta, and optional error
{
const withOptionalPayloadOptionalMetaAndOptionalError = (
message?: string,
scope?: string,
error?: boolean
) => action('ACTION', message, scope, error);
// @dts-jest:pass:snap
withOptionalPayloadOptionalMetaAndOptionalError(); // => { type: 'ACTION' }
// @dts-jest:pass:snap
withOptionalPayloadOptionalMetaAndOptionalError('Hello!'); // => { type: 'ACTION', payload: 'Hello!' }
// @dts-jest:pass:snap
withOptionalPayloadOptionalMetaAndOptionalError('Hello!', 'info'); // => { type: 'ACTION', payload: 'Hello!', meta: 'info' }
// @dts-jest:pass:snap
withOptionalPayloadOptionalMetaAndOptionalError('Hello!', 'info', true); // => { type: 'ACTION', payload: 'Hello!', meta: 'info', error: true }
}