-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(@aws-amplify/ui-react): withAuthenticator returns Component (#5327)
* withAuthenticator should return a Component, not an element * Fix withAuthenticator stories to return Component * Add jest testing * Add missing type for props * Add withAuthenticator test * Fix stories to render HoC, not just return it
- Loading branch information
1 parent
767025f
commit 01e21ef
Showing
5 changed files
with
37 additions
and
17 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
packages/amplify-ui-react/__tests__/withAuthenticator-test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import React from 'react'; | ||
import { renderToStaticMarkup } from 'react-dom/server'; | ||
import { withAuthenticator } from '../src/withAuthenticator'; | ||
|
||
const App = () => <h1>My App</h1>; | ||
|
||
describe('withAuthenticator', () => { | ||
it('should wrap App with AmplifyAuthenticator', () => { | ||
const Wrapped = withAuthenticator(App); | ||
|
||
expect(renderToStaticMarkup(<Wrapped />)).toMatchInlineSnapshot( | ||
`"<amplify-authenticator><h1>My App</h1></amplify-authenticator>"` | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports = { | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,20 @@ | ||
import React, { ComponentType, ComponentPropsWithRef } from 'react'; | ||
import React, { | ||
ComponentType, | ||
ComponentPropsWithRef, | ||
FunctionComponent, | ||
} from 'react'; | ||
|
||
import { AmplifyAuthenticator } from './'; | ||
|
||
export function withAuthenticator( | ||
Component: ComponentType, | ||
props?: ComponentPropsWithRef<typeof AmplifyAuthenticator> | ||
authenticatorProps?: ComponentPropsWithRef<typeof AmplifyAuthenticator> | ||
) { | ||
return ( | ||
<AmplifyAuthenticator {...props}> | ||
const ComponentWithAuthenticator: FunctionComponent = props => ( | ||
<AmplifyAuthenticator {...authenticatorProps} {...props}> | ||
<Component /> | ||
</AmplifyAuthenticator> | ||
); | ||
|
||
return ComponentWithAuthenticator; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters