Skip to content

Commit 3785f00

Browse files
committed
fix(components/base_component): Components without an init() function are not renderable
1 parent bf547b1 commit 3785f00

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/components/base_component.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ const render_component = (args, instance_args, ...rest) =>
7575
const create_element = (init_func, instance_args, selection) => {
7676
try {
7777
return (typeof init_func === 'function')
78-
? init_func(instance_args, selection) : null
78+
? init_func(instance_args, selection) : selection.append('span')
7979
} catch(error) {
8080
selection.call(show_error_message(error))
8181
}

src/components/base_component.test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,12 @@ describe('Component', function() {
170170
my_render.should.be.calledWith({}, my_selection, [1])
171171
})
172172

173+
it('if there is no init() function, a <span> is created', () => {
174+
const { my_init } = call_test_component_with(
175+
{'instance_args': {}, 'has_init': false})
176+
d3.selectAll('span').size().should.equal(1)
177+
})
178+
173179
it('if there is an init() function, it should be called', () => {
174180
const { my_init } = call_test_component_with(
175181
{'instance_args': {}, 'has_init': true})

0 commit comments

Comments
 (0)