1313
1414import * as React from 'react' ;
1515
16- const createAnimatedComponent = require ( '../createAnimatedComponent' ) . default ;
16+ let Animated = require ( '../Animated' ) . default ;
17+ const createAnimatedComponent_EXPERIMENTAL =
18+ require ( '../createAnimatedComponent_EXPERIMENTAL' ) . default ;
1719const createAnimatedComponentInjection = require ( '../createAnimatedComponentInjection' ) ;
20+ let TestRenderer = require ( 'react-test-renderer' ) ;
21+
22+ let callback ;
1823
1924function injected < TProps : { ...} , TInstance > (
2025 Component : React . AbstractComponent < TProps , TInstance > ,
2126) : React . AbstractComponent < TProps , TInstance > {
22- return createAnimatedComponent ( Component ) ;
27+ callback ( ) ;
28+ return createAnimatedComponent_EXPERIMENTAL ( Component ) ;
2329}
2430
2531beforeEach ( ( ) => {
2632 jest . resetModules ( ) ;
2733 jest . resetAllMocks ( ) ;
34+ callback = jest . fn ( ) ;
2835} ) ;
2936
3037test ( '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 ) ;
3341} ) ;
3442
3543test ( 'injection overrides `createAnimatedComponent`' , ( ) => {
3644 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 ) ;
3948} ) ;
4049
4150test ( 'injection errors if called too late' , ( ) => {
4251 jest . spyOn ( console , 'error' ) . mockReturnValue ( undefined ) ;
4352
44- // Causes `createAnimatedComponent` to be initialized.
45- createAnimatedComponent ;
53+ const opacity = new Animated . Value ( 0 ) ;
54+ TestRenderer . create ( < Animated . View style = { { opacity } } /> ) ;
4655
4756 createAnimatedComponentInjection . inject ( injected ) ;
4857
49- expect ( createAnimatedComponent ) . not . toBe ( injected ) ;
58+ expect ( callback . mock . calls . length ) . toBe ( 0 ) ;
59+
5060 expect ( console . error ) . toBeCalledWith (
5161 'createAnimatedComponentInjection: Must be called before `createAnimatedComponent`.' ,
5262 ) ;
@@ -57,7 +67,10 @@ test('injection errors if called more than once', () => {
5767
5868 createAnimatedComponentInjection . inject ( injected ) ;
5969
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+
6174 expect ( console . error ) . not . toBeCalled ( ) ;
6275
6376 createAnimatedComponentInjection . inject ( injected ) ;
0 commit comments