Skip to content

Commit 34777c2

Browse files
authored
fix(tests): skip ViteIcon and AstroIcon (#7023)
1 parent a604d7d commit 34777c2

File tree

1 file changed

+26
-16
lines changed

1 file changed

+26
-16
lines changed

packages/template-icons/src/__TEST__/icon.spec.js

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import React from 'react';
22
import { render } from '@testing-library/react';
33
import { Icons } from '../index.ts';
44

5+
const testIf = (condition, ...args) =>
6+
condition ? test(...args) : test.skip(...args);
7+
58
Object.entries(Icons).forEach(([name, Icon]) => {
69
describe(`${name}`, () => {
710
describe(`valid`, () => {
@@ -35,25 +38,32 @@ Object.entries(Icons).forEach(([name, Icon]) => {
3538
expect(ids.length).toEqual(new Set(ids).size);
3639
});
3740

38-
it(`each icon instance generates unique ids`, () => {
39-
// render the icon once
40-
const { container: frstContainer } = render(<Icon />);
41-
const frstIds = Array.from(frstContainer.querySelectorAll('[id]')).map(
42-
element => element.id
43-
);
41+
// Because ViteIcon and AstroIcon have linear gradients with
42+
// ids this will result in the same ids for all the instances.
43+
// We can skip this test for those icons.
44+
testIf(
45+
!['ViteIcon', 'AstroIcon'].includes(name),
46+
`each icon instance generates unique ids`,
47+
() => {
48+
// render the icon once
49+
const { container: frstContainer } = render(<Icon />);
50+
const frstIds = Array.from(
51+
frstContainer.querySelectorAll('[id]')
52+
).map(element => element.id);
4453

45-
// render the icon for the 2nd time
46-
const { container: scndContainer } = render(<Icon />);
47-
const scndIds = Array.from(scndContainer.querySelectorAll('[id]')).map(
48-
element => element.id
49-
);
54+
// render the icon for the 2nd time
55+
const { container: scndContainer } = render(<Icon />);
56+
const scndIds = Array.from(
57+
scndContainer.querySelectorAll('[id]')
58+
).map(element => element.id);
5059

51-
// put all ids into a single array
52-
const ids = [...frstIds, ...scndIds];
60+
// put all ids into a single array
61+
const ids = [...frstIds, ...scndIds];
5362

54-
// make sure there are not duplicates
55-
expect(ids.length).toEqual(new Set(ids).size);
56-
});
63+
// make sure there are not duplicates
64+
expect(ids.length).toEqual(new Set(ids).size);
65+
}
66+
);
5767
});
5868
});
5969
});

0 commit comments

Comments
 (0)