Skip to content

Commit

Permalink
Add test for serverSide=true with xhr
Browse files Browse the repository at this point in the history
When we render after xhr requests, we check against previous props to determine if we need another update to the UI. This test ensures that the check happens as it should and that the UI does update the display of data.
  • Loading branch information
gabrielliwerant committed May 8, 2019
1 parent 939acac commit ac2986f
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions test/MUIDataTable.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,21 @@ describe('<MUIDataTable />', function() {
assert.deepEqual(JSON.stringify(state.displayData), displayData);
});

it('should correctly re-build display after xhr with serverSide=true', done => {
const fullWrapper = mount(<MUIDataTable columns={columns} data={[]} options={{ serverSide: true }} />);
assert.strictEqual(fullWrapper.find('tbody tr').length, 1);

// simulate xhr and test number of displayed rows
new Promise((resolve, reject) => {
setTimeout(() => {
fullWrapper.setProps({ data });
fullWrapper.update();
assert.strictEqual(fullWrapper.find('tbody tr').length, 4);
done();
}, 10);
});
});

it('should correctly re-build internal table data and displayData structure with prop change', () => {
const shallowWrapper = shallow(<MUIDataTable columns={columns} data={data} />);
let state = shallowWrapper.dive().state();
Expand Down

0 comments on commit ac2986f

Please sign in to comment.