-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: ensure typing for static properties defined on third-party compo…
…nents wrapped by styled-components (#4141) * fix access to static attributes for components structure used in some UI library * test: add type test as well --------- Co-authored-by: Martin PELCAT <[email protected]> Co-authored-by: Evan Jacobs <[email protected]>
- Loading branch information
1 parent
01a8d91
commit 6ee6c23
Showing
4 changed files
with
56 additions
and
11 deletions.
There are no files selected for viewing
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
10 changes: 0 additions & 10 deletions
10
packages/styled-components/src/constructors/test/styled.test.ts
This file was deleted.
Oops, something went wrong.
49 changes: 49 additions & 0 deletions
49
packages/styled-components/src/constructors/test/styled.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,49 @@ | ||
import React, { ComponentProps } from 'react'; | ||
import TestRenderer from 'react-test-renderer'; | ||
import { getRenderedCSS, resetStyled } from '../../test/utils'; | ||
import domElements from '../../utils/domElements'; | ||
|
||
let styled: ReturnType<typeof resetStyled>; | ||
|
||
describe('styled', () => { | ||
beforeEach(() => { | ||
styled = resetStyled(); | ||
}); | ||
|
||
it('should have all valid HTML5 elements defined as properties', () => { | ||
domElements.forEach(domElement => { | ||
expect(styled[domElement]).toBeTruthy(); | ||
}); | ||
}); | ||
|
||
it('should expose the component static attribute like components', () => { | ||
const CollapseComponent = (props: ComponentProps<'div'>) => { | ||
return <div {...props} />; | ||
}; | ||
|
||
const Panel = (props: ComponentProps<'div'>) => { | ||
return <div {...props} />; | ||
}; | ||
|
||
const Collapse = Object.assign(CollapseComponent, { Panel, PI: '3.14' }); | ||
|
||
const StyledCollapse = styled(Collapse)` | ||
background: red; | ||
`; | ||
|
||
expect(Collapse).toBeTruthy(); | ||
expect(Collapse.Panel).toBeTruthy(); | ||
expect(Collapse.PI).toBe('3.14'); | ||
|
||
expect(StyledCollapse).toBeTruthy(); | ||
expect(StyledCollapse.Panel).toBeTruthy(); | ||
expect(StyledCollapse.PI).toBe('3.14'); | ||
|
||
TestRenderer.create(<StyledCollapse />); | ||
expect(getRenderedCSS()).toMatchInlineSnapshot(` | ||
".b { | ||
background: red; | ||
}" | ||
`); | ||
}); | ||
}); |
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