Skip to content

Commit

Permalink
Add functional component tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yuqu committed Oct 23, 2020
1 parent 2ce55cb commit 7042b5f
Show file tree
Hide file tree
Showing 10 changed files with 91 additions and 5 deletions.
19 changes: 19 additions & 0 deletions test/__snapshots__/functional.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Connected Components React Plugin - Functional ComponentWithChildren.jsx snippet creation 1`] = `
Object {
"description": "",
"lang": "jsx",
"snippet": "<MyComponent>
{children}
</MyComponent>",
}
`;

exports[`Connected Components React Plugin - Functional FunctionalComponents.jsx snippet creation 1`] = `
Object {
"description": "",
"lang": "jsx",
"snippet": "<MyComponent />",
}
`;
29 changes: 29 additions & 0 deletions test/functional.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import Plugin from "../src";

describe("Connected Components React Plugin - Functional", () => {
test("FunctionalComponents.jsx snippet creation", async () => {
const plugin = new Plugin();

const componentCode = await plugin.process(
{
path: "test/samples/jsx-functional/FunctionalComponent.jsx",
zeplinNames: []
}
);

expect(componentCode).toMatchSnapshot();
});

test("ComponentWithChildren.jsx snippet creation", async () => {
const processor = new Plugin();

const componentCode = await processor.process(
{
path: "test/samples/jsx-functional/FunctionalComponentWithChildren.jsx",
zeplinNames: []
}
);

expect(componentCode).toMatchSnapshot();
});
});
10 changes: 5 additions & 5 deletions test/propType.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ describe("Connected Components React Plugin - PropTypes", () => {

const componentCode = await plugin.process(
{
path: "test/samples/Component.jsx",
path: "test/samples/jsx-class/Component.jsx",
zeplinNames: []
}
);
Expand All @@ -19,7 +19,7 @@ describe("Connected Components React Plugin - PropTypes", () => {

const componentCode = await processor.process(
{
path: "test/samples/ComponentWithChildren.jsx",
path: "test/samples/jsx-class/ComponentWithChildren.jsx",
zeplinNames: []
}
);
Expand All @@ -32,7 +32,7 @@ describe("Connected Components React Plugin - PropTypes", () => {

const componentCode = await processor.process(
{
path: "test/samples/ComponentWithProps.jsx",
path: "test/samples/jsx-class/ComponentWithProps.jsx",
zeplinNames: []
}
);
Expand All @@ -45,7 +45,7 @@ describe("Connected Components React Plugin - PropTypes", () => {

const componentCode = await processor.process(
{
path: "test/samples/ComponentWithChildrenAndProps.jsx",
path: "test/samples/jsx-class/ComponentWithChildrenAndProps.jsx",
zeplinNames: []
}
);
Expand All @@ -58,7 +58,7 @@ describe("Connected Components React Plugin - PropTypes", () => {

const componentCode = await processor.process(
{
path: "test/samples/ComponentWithMemoization.jsx",
path: "test/samples/jsx-class/ComponentWithMemoization.jsx",
zeplinNames: []
}
);
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
17 changes: 17 additions & 0 deletions test/samples/jsx-functional/FunctionalComponent.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from 'react';

const MyComponent = () => {
const thing = {
stuff: 'stuff',
};

const string = thing?.stuff;

return (
<div>
{string}
</div>
);
};

export default MyComponent;
21 changes: 21 additions & 0 deletions test/samples/jsx-functional/FunctionalComponentWithChildren.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React from 'react';

const MyComponent = () => {
const thing = {
stuff: 'stuff',
};

const string = thing?.stuff;

return (
<div>
{string}
</div>
);
};

MyComponent.propTypes = {
children: PropTypes.element.isRequired
};

export default MyComponent;

0 comments on commit 7042b5f

Please sign in to comment.