-
-
Notifications
You must be signed in to change notification settings - Fork 97
/
create-custom-action.spec.ts
69 lines (62 loc) · 1.88 KB
/
create-custom-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
import * as T from './type-helpers';
import { createCustomAction } from './create-custom-action';
// @dts-jest:group toString() method return a type
{
const actionCreator = createCustomAction('CREATE_CUSTOM_ACTION');
// @dts-jest:pass:snap
actionCreator.toString(); // => 'CREATE_CUSTOM_ACTION'
}
// @dts-jest:group with symbol
{
const CREATE_CUSTOM_ACTION = Symbol(1);
const withSymbol = createCustomAction(CREATE_CUSTOM_ACTION as any);
// @dts-jest:pass:snap
withSymbol(); // => { type: CREATE_CUSTOM_ACTION }
}
// @dts-jest:group with type only
{
const withTypeOnly = createCustomAction('CREATE_CUSTOM_ACTION');
// @dts-jest:pass:snap
withTypeOnly(); // => { type: 'CREATE_CUSTOM_ACTION' }
}
// @dts-jest:group with payload
{
const withPayload = createCustomAction(
'CREATE_CUSTOM_ACTION',
(id: number) => ({ payload: id })
);
// @dts-jest:pass:snap
withPayload(1); // => { type: 'CREATE_CUSTOM_ACTION', payload: 1 }
}
// @dts-jest:group with optional payload
{
const withOptionalPayload = createCustomAction(
'CREATE_CUSTOM_ACTION',
(id?: number) => ({ payload: id })
);
// @dts-jest:pass:snap
withOptionalPayload(); // => { type: 'CREATE_CUSTOM_ACTION' }
// @dts-jest:pass:snap
withOptionalPayload(1); // => { type: 'CREATE_CUSTOM_ACTION', payload: 1 }
}
// @dts-jest:group with meta
{
const withMeta = createCustomAction(
'CREATE_CUSTOM_ACTION',
(token: string) => ({ meta: token })
);
// @dts-jest:pass:snap
withMeta('token'); // => { type: 'CREATE_CUSTOM_ACTION', meta: 'token' }
}
// @dts-jest:group with payload and meta
{
const withPayloadAndMeta = createCustomAction(
'CREATE_CUSTOM_ACTION',
(message: string, scope: string) => ({
payload: message,
meta: scope,
})
);
// @dts-jest:pass:snap
withPayloadAndMeta('Hello!', 'info'); // => { type: 'CREATE_CUSTOM_ACTION', payload: 'Hello!', meta: 'info' }
}