Skip to content

Commit 1ed9d85

Browse files
add unit test demonstrating undefined currentPage in componentWillReceiveProps
1 parent b4dc902 commit 1ed9d85

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

tests/reactable_test.jsx

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2580,4 +2580,35 @@ describe('Reactable', function() {
25802580
});
25812581
});
25822582
})
2583+
2584+
describe('receive props with no currentPage', () => {
2585+
let parent;
2586+
2587+
before(function () {
2588+
//create a wrapper component so we can update its state and trigger componentWillReceiveProps in the table
2589+
var TestParent = React.createFactory(React.createClass({
2590+
render() {
2591+
return (<Reactable.Table className="table" id="table" ref="table">
2592+
<Reactable.Tr>
2593+
<Reactable.Td column="Name">
2594+
<b>Griffin Smith</b>
2595+
</Reactable.Td>
2596+
</Reactable.Tr>
2597+
</Reactable.Table>);
2598+
}
2599+
}));
2600+
2601+
parent = ReactDOM.render(TestParent(), ReactableTestUtils.testNode());
2602+
});
2603+
2604+
after(ReactableTestUtils.resetTestEnvironment);
2605+
2606+
it('keeps the same currentPage and does not set it to undefined', function() {
2607+
const preUpdateCurrentPage = parent.refs.table.state.currentPage;
2608+
parent.setState({testState: "this state update will trigger componentWillReceiveProps in the Reactable.Table"});
2609+
const postUpdateCurrentPage = parent.refs.table.state.currentPage;
2610+
expect(postUpdateCurrentPage).to.not.eq(undefined);
2611+
expect(postUpdateCurrentPage).to.eq(preUpdateCurrentPage);
2612+
});
2613+
});
25832614
});

0 commit comments

Comments
 (0)