-
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
useResponsiveProps: Fixes default breakpoint props assignment on SSR
- Loading branch information
1 parent
a2f3d76
commit 081f909
Showing
2 changed files
with
78 additions
and
21 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
packages/atomic-layout/src/hooks/useResponsiveComponent.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,34 @@ | ||
/** | ||
* @jest-environment node | ||
*/ | ||
import React from 'react' | ||
import { renderToString } from 'react-dom/server' | ||
import useResponsiveComponent from './useResponsiveComponent' | ||
|
||
const Component = useResponsiveComponent((props) => { | ||
return <img {...props} /> | ||
}) | ||
|
||
describe('useResponsiveComponent', () => { | ||
describe('given rendered on a server', () => { | ||
let html: ReturnType<typeof renderToString> | ||
|
||
beforeAll(() => { | ||
html = renderToString( | ||
<Component src="image.png" altMd="Image" titleLgDown="Title" />, | ||
) | ||
}) | ||
|
||
it('should have responsive prop with default breakpoint', () => { | ||
expect(html).toContain('src="image.png"') | ||
}) | ||
|
||
it.skip('should have responsive prop with "down" behavior', () => { | ||
expect(html).toContain('title="Title"') | ||
}) | ||
|
||
it('should not have any responsive prop with other breakpoints', () => { | ||
expect(html).not.toContain('alt') | ||
}) | ||
}) | ||
}) |
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