@@ -58,10 +58,9 @@ describe('Expect the <Parallax> component', () => {
58
58
) ;
59
59
} ) ;
60
60
61
- // fix this
62
- it . skip ( 'to create an element in the controller on mount' , ( ) => {
61
+ it ( 'to create an element in the controller on mount' , ( ) => {
63
62
const controller = ParallaxController . init ( { scrollAxis : VERTICAL } ) ;
64
- controller . createElement = jest . fn ( ) ;
63
+ controller . createElement = jest . fn ( controller . createElement ) ;
65
64
66
65
render (
67
66
< MockProvider controllerMock = { controller } >
@@ -72,18 +71,8 @@ describe('Expect the <Parallax> component', () => {
72
71
) ;
73
72
74
73
expect ( controller . createElement ) . toBeCalledWith ( {
75
- elInner : (
76
- < div className = "parallax-inner" >
77
- < div />
78
- </ div >
79
- ) ,
80
- elOuter : (
81
- < div className = "parallax-outer" >
82
- < div className = "parallax-inner" >
83
- < div />
84
- </ div >
85
- </ div >
86
- ) ,
74
+ elInner : expect . any ( HTMLElement ) ,
75
+ elOuter : expect . any ( HTMLElement ) ,
87
76
props : { disabled : false , x0 : 0 , x1 : 0 , y0 : - 100 , y1 : 100 } ,
88
77
} ) ;
89
78
} ) ;
@@ -104,72 +93,85 @@ describe('Expect the <Parallax> component', () => {
104
93
expect ( controller . removeElementById ) . toBeCalledWith ( element . id ) ;
105
94
} ) ;
106
95
107
- // fix this
108
- it . skip ( 'to update an element in the controller when receiving relevant new props' , ( ) => {
96
+ it ( 'to update an element in the controller when receiving relevant new props' , ( ) => {
109
97
const controller = ParallaxController . init ( { scrollAxis : VERTICAL } ) ;
110
98
controller . updateElementPropsById = jest . fn ( ) ;
111
99
112
- class StateChanger extends React . Component {
113
- state = { disabled : false } ;
114
- render ( ) {
115
- return < Parallax { ...this . state } /> ;
116
- }
100
+ function Wrapper ( props ) {
101
+ return (
102
+ < MockProvider controllerMock = { controller } >
103
+ { props . children }
104
+ </ MockProvider >
105
+ ) ;
117
106
}
118
107
119
- let stateInstance ;
120
- render (
121
- < MockProvider controllerMock = { controller } >
122
- < StateChanger ref = { ( ref ) => ( stateInstance = ref ) } />
123
- </ MockProvider >
124
- ) ;
108
+ const { rerender } = render ( < Parallax disabled = { true } /> , {
109
+ wrapper : Wrapper ,
110
+ } ) ;
125
111
126
- const testProps = {
127
- disabled : true ,
128
- x : [ 100 , - 100 ] ,
129
- y : [ - 100 , 100 ] ,
130
- } ;
112
+ rerender ( < Parallax disabled = { false } x = { [ 100 , - 100 ] } y = { [ - 100 , 100 ] } /> ) ;
131
113
132
- // trigger an update
133
- stateInstance . setState ( testProps ) ;
134
114
const element = controller . getElements ( ) [ 0 ] ;
135
115
136
116
expect ( controller . updateElementPropsById ) . toBeCalledWith ( element . id , {
137
- disabled : true ,
117
+ disabled : false ,
138
118
x0 : 100 ,
139
119
x1 : - 100 ,
140
120
y0 : - 100 ,
141
121
y1 : 100 ,
142
122
} ) ;
143
123
144
- // should not be called again
145
- stateInstance . setState ( {
146
- ...testProps ,
147
- foo : false ,
148
- bar : true ,
124
+ const newProps = { disabled : false , x : [ - 40 , - 60 ] , y : [ 10 , 80 ] } ;
125
+
126
+ rerender (
127
+ < Parallax disabled = { newProps . disabled } x = { newProps . x } y = { newProps . y } />
128
+ ) ;
129
+
130
+ expect ( controller . updateElementPropsById ) . toBeCalledWith ( element . id , {
131
+ disabled : false ,
132
+ x0 : - 40 ,
133
+ x1 : - 60 ,
134
+ y0 : 10 ,
135
+ y1 : 80 ,
149
136
} ) ;
150
137
151
- expect ( controller . updateElementPropsById ) . toHaveBeenCalledTimes ( 1 ) ;
138
+ // only update with valid props
139
+ rerender (
140
+ < Parallax
141
+ disabled = { newProps . disabled }
142
+ x = { newProps . x }
143
+ y = { newProps . y }
144
+ // @ts -expect-error
145
+ nope = "bad"
146
+ />
147
+ ) ;
148
+
149
+ expect ( controller . updateElementPropsById ) . toHaveBeenCalledTimes ( 2 ) ;
152
150
} ) ;
153
- // fix this
154
- it . skip ( 'to reset styles on an element if the disabled prop is true' , ( ) => {
151
+
152
+ it ( 'to reset styles on an element if the disabled prop is true' , ( ) => {
155
153
const controller = ParallaxController . init ( { scrollAxis : VERTICAL } ) ;
156
154
controller . resetElementStyles = jest . fn ( ) ;
157
155
158
- class StateChanger extends React . Component {
159
- state = { disabled : false } ;
160
- render ( ) {
161
- return < Parallax { ...this . state } /> ;
162
- }
156
+ function Wrapper ( props ) {
157
+ return (
158
+ < MockProvider controllerMock = { controller } >
159
+ { props . children }
160
+ </ MockProvider >
161
+ ) ;
163
162
}
164
163
165
- let stateInstance ;
166
- render (
167
- < MockProvider controllerMock = { controller } >
168
- < StateChanger ref = { ( ref ) => ( stateInstance = ref ) } />
169
- </ MockProvider >
164
+ const offX = [ 100 , - 100 ] ;
165
+ const offY = [ 100 , - 100 ] ;
166
+
167
+ const { rerender } = render (
168
+ < Parallax disabled = { false } x = { offX } y = { offY } /> ,
169
+ {
170
+ wrapper : Wrapper ,
171
+ }
170
172
) ;
171
173
172
- stateInstance . setState ( { disabled : true } ) ;
174
+ rerender ( < Parallax disabled = { true } x = { offX } y = { offY } /> ) ;
173
175
174
176
expect ( controller . resetElementStyles ) . toBeCalled ( ) ;
175
177
} ) ;
0 commit comments