Skip to content

Commit befe810

Browse files
committed
Do not throw an exception when checked or expanded arrays contain invalid values
Resolves #69.
1 parent 3181188 commit befe810

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# CHANGELOG
22

3+
## v1.2.0 (TBA)
4+
5+
### Other
6+
7+
* [#69]: Tree will no longer throw an exception if `checked` or `expanded` contains values that do not recursively exist in the `nodes` property
8+
39
## [v1.1.0](https://github.com/jakezatecky/react-checkbox-tree/compare/v1.0.2...v1.1.0) (2018-03-31)
410

511
### New Features

src/js/CheckboxTree.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,9 @@ class CheckboxTree extends React.Component {
164164
// Unserialize values and set their nodes to true
165165
Object.keys(lists).forEach((listKey) => {
166166
lists[listKey].forEach((value) => {
167-
this.nodes[value][listKey] = true;
167+
if (this.nodes[value] !== undefined) {
168+
this.nodes[value][listKey] = true;
169+
}
168170
});
169171
});
170172
}

test/CheckboxTree.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,19 @@ describe('<CheckboxTree />', () => {
2222
});
2323
});
2424

25+
describe('checked', () => {
26+
it('should not throw an exception if it contains values that are not in the `nodes` property', () => {
27+
const wrapper = shallow(
28+
<CheckboxTree
29+
checked={['neptune']}
30+
nodes={[{ value: 'jupiter', label: 'Jupiter' }]}
31+
/>,
32+
);
33+
34+
assert.isTrue(wrapper.find('.react-checkbox-tree').exists());
35+
});
36+
});
37+
2538
describe('disabled', () => {
2639
it('should add the class rct-disabled to the root', () => {
2740
const wrapper = shallow(
@@ -32,6 +45,19 @@ describe('<CheckboxTree />', () => {
3245
});
3346
});
3447

48+
describe('expanded', () => {
49+
it('should not throw an exception if it contains values that are not in the `nodes` property', () => {
50+
const wrapper = shallow(
51+
<CheckboxTree
52+
expanded={['mars']}
53+
nodes={[{ value: 'jupiter', label: 'Jupiter' }]}
54+
/>,
55+
);
56+
57+
assert.isTrue(wrapper.find('.react-checkbox-tree').exists());
58+
});
59+
});
60+
3561
describe('nativeCheckboxes', () => {
3662
it('should add the class rct-native-display to the root', () => {
3763
const wrapper = shallow(

0 commit comments

Comments
 (0)