Skip to content

Commit

Permalink
Merge pull request #103 from martpie/test-react-components
Browse files Browse the repository at this point in the history
Add integration test for a TypeScript react component
  • Loading branch information
martpie authored Aug 10, 2020
2 parents 543a0de + 45a46c1 commit 0274663
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 3 deletions.
9 changes: 9 additions & 0 deletions src/__tests__/__apps__/_shared-ts/components/Subtitle.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from 'react';

type Props = {
underlined: boolean;
};

export const Subtitle: React.FC<Props> = (props) => {
return <h2 style={{ textDecoration: props.underlined ? 'underline' : 'none' }}>{props.children}</h2>;
};
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import React from 'react';
import { add } from 'shared-ts/utils/calc';
import { Subtitle } from 'shared-ts/components/Subtitle';

const HomePage: React.FC = () => {
return <h1>The answer is {add(40, 3)}</h1>;
return (
<>
<h1>The answer is {add(40, 3)}</h1>
<Subtitle underlined>And this is a subtitle</Subtitle>
</>
);
};

export default HomePage;
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from 'react';

type Props = {
underlined: boolean;
};

export const Subtitle: React.FC<Props> = (props) => {
return <h2 style={{ textDecoration: props.underlined ? 'underline' : 'none' }}>{props.children}</h2>;
};
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import React from 'react';
import { add } from 'shared-ts/utils/calc';
import { Subtitle } from 'shared-ts/components/Subtitle';

const HomePage: React.FC = () => {
return <h1>The answer is {add(40, 3)}</h1>;
return (
<div>
<h1>The answer is {add(40, 3)}</h1>
<Subtitle underlined>And this is a subtitle</Subtitle>
</div>
);
};

export default HomePage;
5 changes: 4 additions & 1 deletion src/__tests__/integrations.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe.each([
});

describe('local-typescript-module transpilation', () => {
test('pages using transpiled modules should be correctly displayed', async () => {
test('pages using transpiled modules (helpers or React components) should be correctly displayed', async () => {
const page = await browser.newPage();
const response = await page.goto(`${BASE_URL}/test-local-typescript-module`);

Expand All @@ -50,6 +50,9 @@ describe.each([

const content = await page.$eval('h1', (e) => e.textContent);
expect(content).toBe('The answer is 43');

const content2 = await page.$eval('h2', (e) => e.textContent);
expect(content2).toBe('And this is a subtitle');
});
});

Expand Down

0 comments on commit 0274663

Please sign in to comment.