File tree 2 files changed +15
-3
lines changed
2 files changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ import sinon from 'sinon';
5
5
import jsdom from 'mocha-jsdom' ;
6
6
7
7
import searchBox from '../search-box' ;
8
+ import EventEmitter from 'events' ;
8
9
9
10
import expectJSX from 'expect-jsx' ;
10
11
expect . extend ( expectJSX ) ;
@@ -31,12 +32,12 @@ describe('search-box()', () => {
31
32
query : ''
32
33
} ;
33
34
helper = {
34
- on : sinon . spy ( ) ,
35
35
setQuery : sinon . spy ( ) ,
36
36
search : sinon . spy ( ) ,
37
37
state : {
38
38
query : ''
39
- }
39
+ } ,
40
+ ...EventEmitter . prototype
40
41
} ;
41
42
} ) ;
42
43
@@ -272,6 +273,17 @@ describe('search-box()', () => {
272
273
} ) ;
273
274
} ) ;
274
275
276
+ it ( 'updates the input on an helper update' , ( ) => {
277
+ container = document . createElement ( 'div' ) ;
278
+ widget = searchBox ( { container} ) ;
279
+ widget . init ( { state, helper} ) ;
280
+ let input = container . querySelector ( 'input' ) ;
281
+ expect ( input . value ) . toBe ( '' ) ;
282
+ input . blur ( ) ;
283
+ helper . emit ( 'change' , { query : 'iphone' } ) ;
284
+ expect ( input . value ) . toBe ( 'iphone' ) ;
285
+ } ) ;
286
+
275
287
context ( 'focus' , ( ) => {
276
288
let input ;
277
289
beforeEach ( ( ) => {
Original file line number Diff line number Diff line change @@ -162,7 +162,7 @@ function searchBox({
162
162
// Update value when query change outside of the input
163
163
helper . on ( 'change' , function ( newState ) {
164
164
if ( input !== document . activeElement && input . value !== newState . query ) {
165
- input . value = state . query ;
165
+ input . value = newState . query ;
166
166
}
167
167
} ) ;
168
168
You can’t perform that action at this time.
0 commit comments