diff --git a/src/common/ScrollToTop.js b/src/common/ScrollToTop.js
index 67ccb7d8..28e776b6 100644
--- a/src/common/ScrollToTop.js
+++ b/src/common/ScrollToTop.js
@@ -7,10 +7,10 @@ const ScrollToTop = ({ scrollTo }) => class ScrollToTop extends React.Component
children: PropTypes.node,
};
- componentDidUpdate(prevProps) {
+ componentDidUpdate({ location: prevLocation }) {
const { location } = this.props;
- if (location !== prevProps.location) {
+ if (location !== prevLocation) {
scrollTo(0, 0);
}
}
diff --git a/test/common/ScrollToTop.test.js b/test/common/ScrollToTop.test.js
new file mode 100644
index 00000000..77d428e5
--- /dev/null
+++ b/test/common/ScrollToTop.test.js
@@ -0,0 +1,29 @@
+import React from 'react';
+import { shallow } from 'enzyme';
+import * as sinon from 'sinon';
+import createScrollToTop from '../../src/common/ScrollToTop';
+
+describe('', () => {
+ let wrapper;
+ const window = {
+ scrollTo: sinon.spy(),
+ };
+
+ beforeEach(() => {
+ const ScrollToTop = createScrollToTop(window);
+
+ wrapper = shallow(Foobar);
+ });
+
+ afterEach(() => {
+ wrapper.unmount();
+ window.scrollTo.resetHistory();
+ });
+
+ it('just renders children', () => expect(wrapper.text()).toEqual('Foobar'));
+
+ it('scrolls to top when location changes', () => {
+ wrapper.instance().componentDidUpdate({ location: { href: 'bar' } });
+ expect(window.scrollTo.calledOnce).toEqual(true);
+ });
+});