Skip to content

Commit b50ba54

Browse files
committed
fix: execute validations on formatted arguments
1 parent 34ae96b commit b50ba54

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

src/components/base_component.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ const handle_external_data = (instance_args, selection, raw_data) => (resolve) =
7575
: resolve(raw_data)
7676

7777
const create_bind_function = (args, instance_args) => (selection) => {
78+
console.log('create bind functin called', args, instance_args, selection) // eslint-disable-line
7879
validate_selection(selection)
7980
let element = create_element(args.init, format_arguments(instance_args), selection)
8081

@@ -106,7 +107,7 @@ const format_arguments = (args) => {
106107
}
107108

108109
const create_component_function = (args) => (instance_args) => {
109-
execute_validations(args.validators)(instance_args)
110+
execute_validations(args.validators)(format_arguments(instance_args))
110111
return create_bind_function(args, instance_args)
111112
}
112113

src/components/base_component.test.js

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)