1
- // flow-typed signature: 5f6b80ba0fa4571aac1e7ea6e5fea425
2
- // flow-typed version: f4a7859cd3/jest_v22 .x.x/flow_>=v0.39.x
1
+ // flow-typed signature: f5a484315a3dea13d273645306e4076a
2
+ // flow-typed version: 7c5d14b3d4/jest_v23 .x.x/flow_>=v0.39.x
3
3
4
4
type JestMockFn < TArguments : $ReadOnlyArray < * > , TReturn > = {
5
5
( ...args : TArguments ) : TReturn ,
@@ -65,13 +65,29 @@ type JestMockFn<TArguments: $ReadOnlyArray<*>, TReturn> = {
65
65
*/
66
66
mockReturnThis ( ) : void ,
67
67
/**
68
- * Deprecated: use jest.fn(() => value) instead
68
+ * Accepts a value that will be returned whenever the mock function is called.
69
69
*/
70
70
mockReturnValue ( value : TReturn ) : JestMockFn < TArguments , TReturn > ,
71
71
/**
72
72
* Sugar for only returning a value once inside your mock
73
73
*/
74
- mockReturnValueOnce ( value : TReturn ) : JestMockFn < TArguments , TReturn >
74
+ mockReturnValueOnce ( value : TReturn ) : JestMockFn < TArguments , TReturn > ,
75
+ /**
76
+ * Sugar for jest.fn().mockImplementation(() => Promise.resolve(value))
77
+ */
78
+ mockResolvedValue ( value : TReturn ) : JestMockFn < TArguments , Promise < TReturn >> ,
79
+ /**
80
+ * Sugar for jest.fn().mockImplementationOnce(() => Promise.resolve(value))
81
+ */
82
+ mockResolvedValueOnce ( value : TReturn ) : JestMockFn < TArguments , Promise < TReturn >> ,
83
+ /**
84
+ * Sugar for jest.fn().mockImplementation(() => Promise.reject(value))
85
+ */
86
+ mockRejectedValue ( value : TReturn ) : JestMockFn < TArguments , Promise < any >> ,
87
+ /**
88
+ * Sugar for jest.fn().mockImplementationOnce(() => Promise.reject(value))
89
+ */
90
+ mockRejectedValueOnce ( value : TReturn ) : JestMockFn < TArguments , Promise < any >>
75
91
} ;
76
92
77
93
type JestAsymmetricEqualityType = {
@@ -124,6 +140,30 @@ type JestPromiseType = {
124
140
*/
125
141
type JestTestName = string | Function ;
126
142
143
+ /**
144
+ * Plugin: jest-styled-components
145
+ */
146
+
147
+ type JestStyledComponentsMatcherValue =
148
+ | string
149
+ | JestAsymmetricEqualityType
150
+ | RegExp
151
+ | typeof undefined ;
152
+
153
+ type JestStyledComponentsMatcherOptions = {
154
+ media ?: string ;
155
+ modifier ? : string ;
156
+ supports ? : string ;
157
+ }
158
+
159
+ type JestStyledComponentsMatchersType = {
160
+ toHaveStyleRule (
161
+ property : string ,
162
+ value : JestStyledComponentsMatcherValue ,
163
+ options ?: JestStyledComponentsMatcherOptions
164
+ ) : void ,
165
+ } ;
166
+
127
167
/**
128
168
* Plugin: jest-enzyme
129
169
*/
@@ -483,8 +523,14 @@ type JestExtendedMatchersType = {
483
523
toIncludeMultiple ( substring : string [ ] ) : void ;
484
524
} ;
485
525
486
- type JestExpectType = {
487
- not : JestExpectType & EnzymeMatchersType & DomTestingLibraryType & JestJQueryMatchersType & JestExtendedMatchersType ,
526
+ interface JestExpectType {
527
+ not :
528
+ & JestExpectType
529
+ & EnzymeMatchersType
530
+ & DomTestingLibraryType
531
+ & JestJQueryMatchersType
532
+ & JestStyledComponentsMatchersType
533
+ & JestExtendedMatchersType ,
488
534
/**
489
535
* If you have a mock function, you can use .lastCalledWith to test what
490
536
* arguments it was last called with.
@@ -495,10 +541,6 @@ type JestExpectType = {
495
541
* strict equality.
496
542
*/
497
543
toBe ( value : any ) : void ,
498
- /**
499
- * Use .toHaveBeenCalled to ensure that a mock function got called.
500
- */
501
- toBeCalled ( ) : void ,
502
544
/**
503
545
* Use .toBeCalledWith to ensure that a mock function was called with
504
546
* specific arguments.
@@ -574,21 +616,55 @@ type JestExpectType = {
574
616
* Use .toHaveBeenCalled to ensure that a mock function got called.
575
617
*/
576
618
toHaveBeenCalled ( ) : void ,
619
+ toBeCalled ( ) : void ;
577
620
/**
578
621
* Use .toHaveBeenCalledTimes to ensure that a mock function got called exact
579
622
* number of times.
580
623
*/
581
624
toHaveBeenCalledTimes ( number : number ) : void ,
625
+ toBeCalledTimes ( number : number ) : void ;
626
+ /**
627
+ *
628
+ */
629
+ toHaveBeenNthCalledWith ( nthCall : number , ...args : Array < any > ) : void ;
630
+ nthCalledWith ( nthCall : number , ...args : Array < any > ) : void ;
631
+ /**
632
+ *
633
+ */
634
+ toHaveReturned ( ) : void ;
635
+ toReturn ( ) : void ;
636
+ /**
637
+ *
638
+ */
639
+ toHaveReturnedTimes ( number : number ) : void ;
640
+ toReturnTimes ( number : number ) : void ;
641
+ /**
642
+ *
643
+ */
644
+ toHaveReturnedWith ( value : any ) : void ;
645
+ toReturnWith ( value : any ) : void ;
646
+ /**
647
+ *
648
+ */
649
+ toHaveLastReturnedWith ( value : any ) : void ;
650
+ lastReturnedWith ( value : any ) : void ;
651
+ /**
652
+ *
653
+ */
654
+ toHaveNthReturnedWith ( nthCall : number , value : any ) : void ;
655
+ nthReturnedWith ( nthCall : number , value : any ) : void ;
582
656
/**
583
657
* Use .toHaveBeenCalledWith to ensure that a mock function was called with
584
658
* specific arguments.
585
659
*/
586
660
toHaveBeenCalledWith ( ...args : Array < any > ) : void ,
661
+ toBeCalledWith ( ...args : Array < any > ) : void ,
587
662
/**
588
663
* Use .toHaveBeenLastCalledWith to ensure that a mock function was last called
589
664
* with specific arguments.
590
665
*/
591
666
toHaveBeenLastCalledWith ( ...args : Array < any > ) : void ,
667
+ lastCalledWith ( ...args : Array < any > ) : void ,
592
668
/**
593
669
* Check that an object has a .length property and it is set to a certain
594
670
* numeric value.
@@ -607,9 +683,20 @@ type JestExpectType = {
607
683
*/
608
684
toMatchObject ( object : Object | Array < Object > ) : void ,
609
685
/**
610
- * This ensures that a React component matches the most recent snapshot.
686
+ * Use .toStrictEqual to check that a javascript object matches a subset of the properties of an object.
687
+ */
688
+ toStrictEqual ( value : any ) : void ,
689
+ /**
690
+ * This ensures that an Object matches the most recent snapshot.
611
691
*/
612
- toMatchSnapshot ( name ? : string ) : void ,
692
+ toMatchSnapshot ( propertyMatchers ?: { [ key : string ] : JestAsymmetricEqualityType } , name ?: string ) : void ,
693
+ /**
694
+ * This ensures that an Object matches the most recent snapshot.
695
+ */
696
+ toMatchSnapshot ( name : string ) : void ,
697
+
698
+ toMatchInlineSnapshot ( snapshot ? : string ) : void ,
699
+ toMatchInlineSnapshot ( propertyMatchers ?: { [ key : string ] : JestAsymmetricEqualityType } , snapshot ?: string ) : void ,
613
700
/**
614
701
* Use .toThrow to test that a function throws when it is called.
615
702
* If you want to test that a specific error gets thrown, you can provide an
@@ -624,8 +711,9 @@ type JestExpectType = {
624
711
* Use .toThrowErrorMatchingSnapshot to test that a function throws a error
625
712
* matching the most recent snapshot when it is called.
626
713
*/
627
- toThrowErrorMatchingSnapshot ( ) : void
628
- } ;
714
+ toThrowErrorMatchingSnapshot ( ) : void ,
715
+ toThrowErrorMatchingInlineSnapshot ( snapshot ? : string ) : void ,
716
+ }
629
717
630
718
type JestObjectType = {
631
719
/**
@@ -843,6 +931,17 @@ declare var it: {
843
931
fn ?: ( done : ( ) => void ) => ?Promise < mixed > ,
844
932
timeout ? : number
845
933
) : void ,
934
+ /**
935
+ * each runs this test against array of argument arrays per each run
936
+ *
937
+ * @param {table } table of Test
938
+ */
939
+ each (
940
+ table : Array < Array < mixed >>
941
+ ) : (
942
+ name : JestTestName ,
943
+ fn ?: ( ...args : Array < any > ) => ?Promise < mixed >
944
+ ) => void ,
846
945
/**
847
946
* Only run this test
848
947
*
@@ -854,7 +953,14 @@ declare var it: {
854
953
name : JestTestName ,
855
954
fn ?: ( done : ( ) => void ) => ?Promise < mixed > ,
856
955
timeout ? : number
857
- ) : void ,
956
+ ) : {
957
+ each (
958
+ table : Array < Array < mixed >>
959
+ ) : (
960
+ name : JestTestName ,
961
+ fn ?: ( ...args : Array < any > ) => ?Promise < mixed >
962
+ ) => void ,
963
+ } ,
858
964
/**
859
965
* Skip running this test
860
966
*
@@ -945,7 +1051,15 @@ type JestPrettyFormatPlugins = Array<JestPrettyFormatPlugin>;
945
1051
/** The expect function is used every time you want to test a value */
946
1052
declare var expect : {
947
1053
/** The object that you want to make assertions against */
948
- ( value : any ) : JestExpectType & JestPromiseType & EnzymeMatchersType & DomTestingLibraryType & JestJQueryMatchersType & JestExtendedMatchersType ,
1054
+ ( value : any ) :
1055
+ & JestExpectType
1056
+ & JestPromiseType
1057
+ & EnzymeMatchersType
1058
+ & DomTestingLibraryType
1059
+ & JestJQueryMatchersType
1060
+ & JestStyledComponentsMatchersType
1061
+ & JestExtendedMatchersType ,
1062
+
949
1063
/** Add additional Jasmine matchers to Jest's roster */
950
1064
extend ( matchers : { [ name : string ] : JestMatcher } ) : void ,
951
1065
/** Add a module that formats application-specific data structures. */
@@ -958,7 +1072,13 @@ declare var expect: {
958
1072
objectContaining ( value : Object ) : Object ,
959
1073
/** Matches any received string that contains the exact expected string. */
960
1074
stringContaining ( value : string ) : string ,
961
- stringMatching ( value : string | RegExp ) : string
1075
+ stringMatching ( value : string | RegExp ) : string ,
1076
+ not : {
1077
+ arrayContaining : ( value : $ReadOnlyArray < mixed > ) => Array < mixed > ,
1078
+ objectContaining : ( value : { } ) => Object ,
1079
+ stringContaining : ( value : string ) => string ,
1080
+ stringMatching : ( value : string | RegExp ) => string ,
1081
+ } ,
962
1082
} ;
963
1083
964
1084
// TODO handle return type
0 commit comments