File tree Expand file tree Collapse file tree 2 files changed +15
-3
lines changed Expand file tree Collapse file tree 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';
55import jsdom from 'mocha-jsdom' ;
66
77import searchBox from '../search-box' ;
8+ import EventEmitter from 'events' ;
89
910import expectJSX from 'expect-jsx' ;
1011expect . extend ( expectJSX ) ;
@@ -31,12 +32,12 @@ describe('search-box()', () => {
3132 query : ''
3233 } ;
3334 helper = {
34- on : sinon . spy ( ) ,
3535 setQuery : sinon . spy ( ) ,
3636 search : sinon . spy ( ) ,
3737 state : {
3838 query : ''
39- }
39+ } ,
40+ ...EventEmitter . prototype
4041 } ;
4142 } ) ;
4243
@@ -272,6 +273,17 @@ describe('search-box()', () => {
272273 } ) ;
273274 } ) ;
274275
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+
275287 context ( 'focus' , ( ) => {
276288 let input ;
277289 beforeEach ( ( ) => {
Original file line number Diff line number Diff line change @@ -162,7 +162,7 @@ function searchBox({
162162 // Update value when query change outside of the input
163163 helper . on ( 'change' , function ( newState ) {
164164 if ( input !== document . activeElement && input . value !== newState . query ) {
165- input . value = state . query ;
165+ input . value = newState . query ;
166166 }
167167 } ) ;
168168
You can’t perform that action at this time.
0 commit comments