Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warn on bad value passed to registerChild in WindowScroller #949

Merged
merged 1 commit into from
Jan 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions source/WindowScroller/WindowScroller.jest.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,20 @@ describe('WindowScroller', () => {
expect(component._positionFromLeft).toEqual(350 + 150 - 250);
});

it('should warn on passing non-element or not null', () => {
const warnFn = jest.spyOn(console, 'warn');
const renderFn = jest.fn();

render(getMarkup({renderFn}));

renderFn.mock.calls[0][0].registerChild(1);
renderFn.mock.calls[0][0].registerChild(document.createElement('div'));
renderFn.mock.calls[0][0].registerChild(null);

expect(warnFn).toHaveBeenCalledTimes(1);
warnFn.mockRestore();
});

// Test edge-case reported in bvaughn/react-virtualized/pull/346
it('should have correct top and left properties to be defined on :_positionFromTop and :_positionFromLeft if documentElement is scrolled', () => {
render.unmount();
Expand Down
5 changes: 5 additions & 0 deletions source/WindowScroller/WindowScroller.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,11 @@ export default class WindowScroller extends React.PureComponent<Props, State> {
}

_registerChild = element => {
if (element && !(element instanceof Element)) {
console.warn(
'WindowScroller registerChild expects to be passed Element or null',
);
}
this._child = element;
this.updatePosition();
};
Expand Down