Skip to content

Commit b3b4b34

Browse files
Fix toHaveCompiledCss crash for SVG elements (#1827)
* Fix toHaveCompiledCss crash for SVG elements * Update .changeset/plain-windows-listen.md Co-authored-by: Kylor Hall <[email protected]> --------- Co-authored-by: Kylor Hall <[email protected]>
1 parent c6aead5 commit b3b4b34

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

.changeset/plain-windows-listen.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@compiled/react': patch
3+
'@compiled/jest': patch
4+
---
5+
6+
Fix `toHaveCompiledCss` in @compiled/jest crashing on SVG elements due to lack of className property and expands tests in `@compiled/react`.

packages/jest/src/matchers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ export function toHaveCompiledCss(
132132
const stylesToFind = mapProperties(properties);
133133
const foundStyles: string[] = [];
134134
const similarStyles: string[] = [];
135-
const classNames = element.className.split(' ');
135+
const classNames = element.classList;
136136

137137
for (const styleElement of styleElements) {
138138
let css = styleElement.textContent || '';

packages/react/src/__tests__/jest-matcher.test.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,19 @@ describe('toHaveCompliedCss', () => {
1818
expect(getByText('hello world')).toHaveCompiledCss('font-size', '12px');
1919
});
2020

21+
it('should detect styles (SVG)', () => {
22+
const { getByText } = render(
23+
<svg
24+
css={{
25+
fontSize: '12px',
26+
}}>
27+
hello world
28+
</svg>
29+
);
30+
31+
expect(getByText('hello world')).toHaveCompiledCss('font-size', '12px');
32+
});
33+
2134
it('should detect missing styles', () => {
2235
const { getByText } = render(<div css={{ fontSize: '12px' }}>hello world</div>);
2336

0 commit comments

Comments
 (0)