Skip to content

Commit

Permalink
Fix TS types, add tests for Network
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredpalmer committed Nov 17, 2017
1 parent de3adb4 commit 5a1f9a4
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/DeviceMotion/DeviceMotion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export interface DeviceMotionProps {
}

export class DeviceMotion extends React.Component<
SharedRenderProps<{}>,
SharedRenderProps<DeviceMotionProps>,
DeviceMotionProps
> {
state: DeviceMotionProps = {
Expand Down
2 changes: 1 addition & 1 deletion src/DeviceOrientation/DeviceOrientation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export interface DeviceOrientationProps {
}

export class DeviceOrientation extends React.Component<
SharedRenderProps<{}>,
SharedRenderProps<DeviceOrientationProps>,
DeviceOrientationProps
> {
state: DeviceOrientationProps = {
Expand Down
2 changes: 1 addition & 1 deletion src/GeoPosition/GeoPosition.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export interface GeoPositionProps {
}

export class GeoPosition extends React.Component<
SharedRenderProps<{}>,
SharedRenderProps<GeoPositionProps>,
GeoPositionProps
> {
geoId: any;
Expand Down
2 changes: 1 addition & 1 deletion src/Locales/Locales.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ declare namespace Intl {
}

export class Locales extends React.Component<
SharedRenderProps<{}>,
SharedRenderProps<LocalesProps>,
LocalesProps
> {
state: LocalesProps = { locale: this.preferredLocales() };
Expand Down
2 changes: 1 addition & 1 deletion src/Network/Network.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export interface NetworkProps {
}

export class Network extends React.Component<
SharedRenderProps<{}>,
SharedRenderProps<NetworkProps>,
NetworkProps
> {
state: NetworkProps = { online: false };
Expand Down
29 changes: 29 additions & 0 deletions src/Network/__tests__/Network.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import * as React from 'react';
import * as ReactDOM from 'react-dom';

import { Network } from '../';

describe('<Network />', () => {
describe('<Network render />', () => {
const node = document.createElement('div');

afterEach(() => {
ReactDOM.unmountComponentAtNode(node);
});

it('receives { x, y } props', () => {
ReactDOM.render(
<Network
render={props => expect(props).toEqual({ online: false }) || null}
/>,
node
);
});

it('renders elements', () => {
ReactDOM.render(<Network render={() => <div>online</div>} />, node);

expect(node.innerHTML.includes('online')).toBe(true);
});
});
});
37 changes: 37 additions & 0 deletions src/Network/__tests__/withNetwork.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import * as React from 'react';
import * as ReactDOM from 'react-dom';

import { withNetwork } from '../';

describe('withNetwork()', () => {
const node = document.createElement('div');

afterEach(() => {
ReactDOM.unmountComponentAtNode(node);
});

it('receives { online } props', () => {
const hello = 'hi';

const WrappedComponent = withNetwork<{ hello: string }>(
props => expect(props).toEqual({ online: false, hello }) || null
);

ReactDOM.render(<WrappedComponent hello={hello} />, node);
});

// it('renders elements and passes thru props', () => {
// const hello = 'hi';

// const WrappedComponent = withNetwork<{ hello: string }>(props => (
// <div>
// x: {props.x}, y: {props.y} {hello}
// </div>
// ));

// ReactDOM.render(<WrappedComponent hello={hello} />, node);

// expect(node.innerHTML.includes('0')).toBe(true);
// expect(node.innerHTML.includes('hi')).toBe(true);
// });
});

0 comments on commit 5a1f9a4

Please sign in to comment.