Skip to content

Commit aec2722

Browse files
committed
test: add <LocationSensor> server tests
1 parent 1868e9a commit aec2722

File tree

3 files changed

+36
-5
lines changed

3 files changed

+36
-5
lines changed
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import {Component, createElement as h} from 'react';
22
import {storiesOf} from '@storybook/react';
33
import {action} from '@storybook/addon-actions';
44
import {linkTo} from '@storybook/addon-links';
5-
import {LocationSensor} from '.';
6-
import ShowDocs from '../../.storybook/ShowDocs'
5+
import {LocationSensor} from '..';
6+
import ShowDocs from '../../../.storybook/ShowDocs'
77

88
class StoryLocationSensroExample extends Component<any, any> {
99
state = {
@@ -36,5 +36,5 @@ class StoryLocationSensroExample extends Component<any, any> {
3636
}
3737

3838
storiesOf('Sensors/LocationSensor', module)
39-
.add('Documentation', () => h(ShowDocs, {name: 'BatterySensor'}))
39+
.add('Documentation', () => h(ShowDocs, {name: 'LocationSensor'}))
4040
.add('Example', () => h(StoryLocationSensroExample));
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import {createElement as h} from 'react';
2+
import {renderToStaticMarkup} from 'react-dom/server';
3+
import {expect} from 'chai';
4+
import {LocationSensor} from '..';
5+
6+
describe('<LocationSensor> SSR', () => {
7+
it('renders without crashing', () => {
8+
const html = renderToStaticMarkup(
9+
<LocationSensor>{(location) =>
10+
<div>foo</div>
11+
}</LocationSensor>
12+
);
13+
14+
expect(html).to.equal('<div>foo</div>');
15+
});
16+
17+
it('returns expected state', () => {
18+
const html = renderToStaticMarkup(
19+
<LocationSensor>{(location) => {
20+
expect(location).to.eql({
21+
trigger: 'load',
22+
length: 1
23+
});
24+
25+
return null;
26+
}}</LocationSensor>
27+
);
28+
});
29+
});

src/LocationSensor/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ const patchHistoryMethod = (method) => {
1818
};
1919
};
2020

21-
patchHistoryMethod('pushState');
22-
patchHistoryMethod('replaceState');
21+
if (isClient) {
22+
patchHistoryMethod('pushState');
23+
patchHistoryMethod('replaceState');
24+
}
2325

2426
export interface ILocationSensorProps {
2527
children?: (ILocationSensorState) => React.ReactElement<any>;

0 commit comments

Comments
 (0)