1
- import { Failure , fold , Initialized , Kinds , Pending , Success } from './index' ;
1
+ import {
2
+ Failure ,
3
+ fold ,
4
+ Initialized ,
5
+ isFailure ,
6
+ isInitialized ,
7
+ isPending ,
8
+ isSuccess ,
9
+ Kinds ,
10
+ Pending ,
11
+ Success ,
12
+ } from './index' ;
2
13
3
14
test ( 'Kinds' , ( ) => {
4
15
expect ( Kinds ) . toEqual ( {
@@ -12,11 +23,15 @@ test('Kinds', () => {
12
23
test ( 'Initialized' , ( ) => {
13
24
expect ( new Initialized ( ) ) . toBeInstanceOf ( Initialized ) ;
14
25
expect ( new Initialized ( ) . kind ) . toEqual ( 'Initialized' ) ;
26
+ expect ( isInitialized ( new Initialized ( ) ) ) . toBeTruthy ( ) ;
27
+ expect ( isInitialized ( new Pending ( ) ) ) . toBeFalsy ( ) ;
15
28
} ) ;
16
29
17
30
test ( 'Pending' , ( ) => {
18
31
expect ( new Pending ( ) ) . toBeInstanceOf ( Pending ) ;
19
32
expect ( new Pending ( ) . kind ) . toEqual ( 'Pending' ) ;
33
+ expect ( isPending ( new Pending ( ) ) ) . toBeTruthy ( ) ;
34
+ expect ( isPending ( new Initialized ( ) ) ) . toBeFalsy ( ) ;
20
35
} ) ;
21
36
22
37
test ( 'Success' , ( ) => {
@@ -25,10 +40,16 @@ test('Success', () => {
25
40
expect ( state ) . toBeInstanceOf ( Success ) ;
26
41
expect ( state . kind ) . toEqual ( 'Success' ) ;
27
42
expect ( state . data ) . toEqual ( data ) ;
43
+ expect ( isSuccess ( state ) ) . toBeTruthy ( ) ;
44
+ expect ( isSuccess ( new Initialized ( ) ) ) . toBeFalsy ( ) ;
28
45
} ) ;
29
46
30
47
test ( 'Success without data' , ( ) => {
31
48
expect ( ( ) => new Success ( ) ) . toThrowError ( 'Parameter "data" is required' ) ;
49
+ expect ( ( ) => new Success ( null ) ) . toThrowError ( 'Parameter "data" is required' ) ;
50
+ expect ( ( ) => new Success ( undefined ) ) . toThrowError (
51
+ 'Parameter "data" is required' ,
52
+ ) ;
32
53
} ) ;
33
54
34
55
test ( 'Failure' , ( ) => {
@@ -37,10 +58,16 @@ test('Failure', () => {
37
58
expect ( state ) . toBeInstanceOf ( Failure ) ;
38
59
expect ( state . kind ) . toEqual ( 'Failure' ) ;
39
60
expect ( state . error ) . toEqual ( error ) ;
61
+ expect ( isFailure ( state ) ) . toBeTruthy ( ) ;
62
+ expect ( isFailure ( new Initialized ( ) ) ) . toBeFalsy ( ) ;
40
63
} ) ;
41
64
42
65
test ( 'Failure without error' , ( ) => {
43
66
expect ( ( ) => new Failure ( ) ) . toThrowError ( 'Parameter "error" is required' ) ;
67
+ expect ( ( ) => new Failure ( null ) ) . toThrowError ( 'Parameter "error" is required' ) ;
68
+ expect ( ( ) => new Failure ( undefined ) ) . toThrowError (
69
+ 'Parameter "error" is required' ,
70
+ ) ;
44
71
} ) ;
45
72
46
73
test ( 'fold initialized' , ( ) => {
0 commit comments