@@ -146,7 +146,7 @@ describe('Hooks', () => {
146
146
expect ( testWrapper . root . findByType ( 'div' ) . children [ 0 ] ) . toBe ( '0' )
147
147
} )
148
148
149
- it . only ( 'should not re-render if return state shallow equaled' , ( ) => {
149
+ it ( 'should not re-render if return state shallow equaled' , ( ) => {
150
150
const fooSpy = Sinon . spy ( )
151
151
const FooComponent = ( ) => {
152
152
const state = useModuleState ( CountModel , {
@@ -196,4 +196,41 @@ describe('Hooks', () => {
196
196
expect ( spy . callCount ) . toBe ( 2 )
197
197
fooSpy . resetHistory ( )
198
198
} )
199
+
200
+ it ( 'should run selector with new closure' , ( ) => {
201
+ const setPlusCountStub = Sinon . stub ( )
202
+ const FooComponent = ( ) => {
203
+ const [ plusCount , setPlusCount ] = useState ( 1 )
204
+ const plusOneCount = useModuleState ( CountModel , {
205
+ selector : ( state ) => plusCount + state . count ,
206
+ dependencies : [ plusCount ] ,
207
+ } )
208
+
209
+ useEffect ( ( ) => {
210
+ setPlusCountStub . callsFake ( ( ) => {
211
+ setPlusCount ( 2 )
212
+ } )
213
+ } , [ ] )
214
+
215
+ return < div > { plusOneCount } </ div >
216
+ }
217
+
218
+ let fooWrapper ! : ReactTestRenderer
219
+ act ( ( ) => {
220
+ fooWrapper = create ( < FooComponent /> )
221
+ } )
222
+
223
+ expect ( fooWrapper . root . findByType ( 'div' ) . children [ 0 ] ) . toBe ( '1' )
224
+ act ( ( ) => {
225
+ setPlusCountStub ( )
226
+ } )
227
+ expect ( fooWrapper . root . findByType ( 'div' ) . children [ 0 ] ) . toBe ( '2' )
228
+
229
+ act ( ( ) => {
230
+ setCountStub ( )
231
+ } )
232
+ expect ( fooWrapper . root . findByType ( 'div' ) . children [ 0 ] ) . toBe ( '12' )
233
+
234
+ setPlusCountStub . reset ( )
235
+ } )
199
236
} )
0 commit comments