Skip to content

Commit

Permalink
testing function expression components
Browse files Browse the repository at this point in the history
  • Loading branch information
melloc01 committed Aug 26, 2021
1 parent 3540cc9 commit 896f8f1
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
12 changes: 12 additions & 0 deletions __tests__/__snapshots__/react-display-name.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,15 @@ function factory(React) {
};
}"
`;

exports[`react-display-name test suite Transforms function expression components 1`] = `
"\\"use strict\\";
function factory(React) {
var MyFunctionComponent = function MyFunctionComponent() {
return /*#__PURE__*/React.createElement(\\"div\\", null, \\"1\\");
};
return MyFunctionComponent;
}"
`;
25 changes: 25 additions & 0 deletions __tests__/react-display-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,29 @@ return factory;

expect(element.type.name).toBe('MyFunctionComponent')
})

it('Transforms function expression components', async () => {
const classComponentInput = `
function factory (React) {
const MyFunctionComponent = () => {
return <div>1</div>
}
return MyFunctionComponent
}
`

const { code: classComponentOutput } = await transformAsync(classComponentInput, options)

expect(classComponentOutput).toMatchSnapshot()

const MyComponentFactory = new Function(`
${classComponentOutput}
return factory;
`)()
const MyComponent = MyComponentFactory(React)
const element = <MyComponent />

expect(element.type.name).toBe('MyFunctionComponent')
})
})

0 comments on commit 896f8f1

Please sign in to comment.