@@ -31,17 +31,19 @@ describe('Component', function() {
3131 . onCall ( 1 ) . returns ( args . element2 )
3232 . returns ( args . element )
3333 const my_render = ( args . render_func === undefined ) ? sinon . spy ( ) : args . render_func
34+ const my_validator = sinon . spy ( )
35+ const validators = [ my_validator ]
3436 const my_component = ( args . has_init === true ) ? Component ( {
35- 'render' : my_render , 'validators' : [ ] , 'init' : my_init
37+ 'render' : my_render , 'validators' : validators , 'init' : my_init
3638 } ) : Component ( {
37- 'render' : my_render , 'validators' : [ ]
39+ 'render' : my_render , 'validators' : validators
3840 } )
3941 const bind = my_component ( args . instance_args )
4042 const d3 = require ( 'd3' )
4143 const my_selection = d3 . selection ( )
4244 const render = bind ( my_selection )
4345 render ( args . data )
44- return { my_init, my_component, my_render, my_selection, render, jq, format_value }
46+ return { my_init, my_component, my_render, my_selection, render, jq, format_value, my_validator }
4547 }
4648
4749 it ( 'should require a render function' , ( ) => {
@@ -335,9 +337,12 @@ describe('Component', function() {
335337 'format_value_return' : {
336338 '22' : [ 'foo' ] ,
337339 'state_handler' : state_handler
340+ } ,
341+ 'format_value_return2' : {
342+ '22' : [ 'foo' ] ,
343+ 'state_handler' : state_handler
338344 }
339345 } )
340- my_init . should . be . called ( )
341346 my_init . should . be . calledWith ( {
342347 '22' : [ 'foo' ] ,
343348 'state_handler' : sinon . match . any
@@ -492,13 +497,25 @@ describe('Component', function() {
492497 'element2' : element2 ,
493498 'format_value_return2' : {
494499 'foo' : 'bar' ,
495- 'state_handler' : sinon . match . any
500+ 'state_handler' : { }
496501 }
497502 } )
498503 state_handler . get_state = ( ) => ( { 'x' : 'foo' , 'y' : 'bar' } )
499504 callback ( state_handler , callback )
500505 my_render . should . be . calledWith ( sinon . match . any , sinon . match . any , sinon . match . any , element2 )
501506 } )
502507
508+ it ( 'returned component should call args validator with formatted args' , ( ) => {
509+ const format_value_return = sinon . spy ( )
510+ const { my_validator } = call_test_component_with ( {
511+ 'instance_args' : { 'state_handler' : {
512+ 'get_state' : sinon . stub ( ) ,
513+ 'subscribe' : sinon . stub ( ) ,
514+ } } ,
515+ 'format_value_return' : format_value_return ,
516+ 'format_value_return2' : format_value_return
517+ } )
518+ my_validator . should . be . alwaysCalledWith ( format_value_return )
519+ } )
503520
504521} )
0 commit comments