Attaching data attributes doesn't work in test
See original GitHub issueAs explained here, I’m trying to attach a data attribute to a styled component, but it doesn’t work.
const Progress = styled(CircularProgress).attrs({
'data-testid': 'progress'
})`
display: inline-flex;
vertical-align: middle;
`;
it('shows a circular progress when passing the loading prop', async () => {
const { getByTestId } = customRender(<SubmitButton loading>Test</SubmitButton>);
const progress = await waitForElement(() => getByTestId('progress'));
expect(progress).toBeInTheDocument();
});
Passes the test: <div data-testid="progress"><Progress color={color} /></div>
Doesn’t pass the test (cannot find the data attribute): <Progress color={color} />
It doesn’t work either if I pass the attribute inline: <Progress color={color} data-testid="progress" />
Tested with Styled Components v4.0.3
Issue Analytics
- State:
- Created 5 years ago
- Reactions:3
- Comments:10 (5 by maintainers)
Top Results From Across the Web
Property injection on attributes not working from a unit test
Filter attribute property injection works as part of the MVC/ASP.NET pipeline, not as something available as a standalone feature.
Read more >Using data attributes - Learn web development | MDN
JavaScript access To get a data attribute through the dataset object, get the property by the part of the attribute name after data-...
Read more >Test Data in Attribute - CodeProject
Attached the test data with method for regression testing by declaring ref type in attribute.
Read more >How to Use HTML Data Attributes - DEV Community
Any HTML element can have any number of data attributes added to its ... “badges” data attached, we could check that data attribute...
Read more >Strategies for working with data attributes in vanilla JavaScript
DO NOT implement this!) document.addEventListener('click', function ( ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Feel free to ask further questions on stack overflow or our spectrum community, Github Issues should just be for bug reports and feature requests. Thanks.
@gazpachu you aren’t spreading the props in your
Comp
component.