13
13
14
14
import * as React from 'react' ;
15
15
16
- const createAnimatedComponent = require ( '../createAnimatedComponent' ) . default ;
16
+ let Animated = require ( '../Animated' ) . default ;
17
+ const createAnimatedComponent_EXPERIMENTAL =
18
+ require ( '../createAnimatedComponent_EXPERIMENTAL' ) . default ;
17
19
const createAnimatedComponentInjection = require ( '../createAnimatedComponentInjection' ) ;
20
+ let TestRenderer = require ( 'react-test-renderer' ) ;
21
+
22
+ let callback ;
18
23
19
24
function injected < TProps : { ...} , TInstance > (
20
25
Component : React . AbstractComponent < TProps , TInstance > ,
21
26
) : React . AbstractComponent < TProps , TInstance > {
22
- return createAnimatedComponent ( Component ) ;
27
+ callback ( ) ;
28
+ return createAnimatedComponent_EXPERIMENTAL ( Component ) ;
23
29
}
24
30
25
31
beforeEach ( ( ) => {
26
32
jest . resetModules ( ) ;
27
33
jest . resetAllMocks ( ) ;
34
+ callback = jest . fn ( ) ;
28
35
} ) ;
29
36
30
37
test ( 'does nothing without injection' , ( ) => {
31
- expect ( typeof createAnimatedComponent ) . toBe ( 'function' ) ;
32
- expect ( createAnimatedComponent ) . not . toBe ( injected ) ;
38
+ const opacity = new Animated . Value ( 0 ) ;
39
+ TestRenderer . create ( < Animated . View style = { { opacity} } /> ) ;
40
+ expect ( callback . mock . calls . length ) . toBe ( 0 ) ;
33
41
} ) ;
34
42
35
43
test ( 'injection overrides `createAnimatedComponent`' , ( ) => {
36
44
createAnimatedComponentInjection . inject ( injected ) ;
37
-
38
- expect ( createAnimatedComponent ) . toBe ( injected ) ;
45
+ const opacity = new Animated . Value ( 0 ) ;
46
+ TestRenderer . create ( < Animated . View style = { { opacity} } /> ) ;
47
+ expect ( callback . mock . calls . length ) . toBe ( 1 ) ;
39
48
} ) ;
40
49
41
50
test ( 'injection errors if called too late' , ( ) => {
42
51
jest . spyOn ( console , 'error' ) . mockReturnValue ( undefined ) ;
43
52
44
- // Causes `createAnimatedComponent` to be initialized.
45
- createAnimatedComponent ;
53
+ const opacity = new Animated . Value ( 0 ) ;
54
+ TestRenderer . create ( < Animated . View style = { { opacity } } /> ) ;
46
55
47
56
createAnimatedComponentInjection . inject ( injected ) ;
48
57
49
- expect ( createAnimatedComponent ) . not . toBe ( injected ) ;
58
+ expect ( callback . mock . calls . length ) . toBe ( 0 ) ;
59
+
50
60
expect ( console . error ) . toBeCalledWith (
51
61
'createAnimatedComponentInjection: Must be called before `createAnimatedComponent`.' ,
52
62
) ;
@@ -57,7 +67,10 @@ test('injection errors if called more than once', () => {
57
67
58
68
createAnimatedComponentInjection . inject ( injected ) ;
59
69
60
- expect ( createAnimatedComponent ) . toBe ( injected ) ;
70
+ const opacity = new Animated . Value ( 0 ) ;
71
+ TestRenderer . create ( < Animated . View style = { { opacity} } /> ) ;
72
+ expect ( callback . mock . calls . length ) . toBe ( 1 ) ;
73
+
61
74
expect ( console . error ) . not . toBeCalled ( ) ;
62
75
63
76
createAnimatedComponentInjection . inject ( injected ) ;
0 commit comments