Skip to content
This repository was archived by the owner on Nov 3, 2025. It is now read-only.

Commit d0c81f2

Browse files
committed
🚧 (canal) Render first page by default
1 parent f5fc34d commit d0c81f2

5 files changed

Lines changed: 37 additions & 3 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`canal renders the first page when mounted 1`] = `<View />`;

src/__tests__/canal.test.ts

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/__tests__/canal.test.tsx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import React from 'react';
2+
import { View } from 'react-native';
3+
import TestRenderer from 'react-test-renderer';
4+
5+
import { canal } from '../canal';
6+
7+
describe('canal', () => {
8+
it('throws an error if first arg is not a Component', () => {
9+
try {
10+
canal('aaa');
11+
} catch (error) {
12+
expect(error.message).toBe(
13+
'`canal` expects its first argument to be a React component. Received type: string'
14+
);
15+
}
16+
expect.assertions(1);
17+
});
18+
19+
it('renders the first page when mounted', () => {
20+
const Canal = canal(View);
21+
const testRenderer = TestRenderer.create(<Canal />);
22+
expect(testRenderer.toJSON()).toMatchSnapshot();
23+
});
24+
});

src/canal.ts

Whitespace-only changes.

src/canal.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import React, { ComponentType, FunctionComponent } from 'react';
2+
3+
export const canal = (Page: ComponentType): FunctionComponent => {
4+
if (!(React.isValidElement(Page) || typeof Page === 'function')) {
5+
throw new Error(
6+
`\`canal\` expects its first argument to be a React component. Received type: ${typeof Page}`
7+
);
8+
}
9+
return () => <Page />;
10+
};

0 commit comments

Comments
 (0)