Skip to content

Commit a668d59

Browse files
authored
validateSelectors: Fix changeset, update tests (#1704)
1 parent 48a9caf commit a668d59

2 files changed

Lines changed: 21 additions & 10 deletions

File tree

.changeset/mighty-ravens-fail.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,14 @@ Allow `:where` and `:is` in `selectors` if all selectors target `&`
66

77
EXAMPLE USAGE:
88

9+
```ts
10+
const whereStyle = style({
11+
color: 'red',
12+
selectors: {
13+
// Valid: all selectors in the list target `whereStyle`
14+
':where(h1 > &, h2 > &)': { color: 'blue' }
15+
// Invalid: the second selector in the list does not target `whereStyle`
16+
':where(h1 > &, h2)': { color: 'blue' }
17+
}
18+
});
19+
```

packages/css/src/validateSelector.test.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ describe('validateSelector', () => {
3838
':is(.target, .a.target)',
3939
':where(.target, .a .target)',
4040
':is(.target, .a .target)',
41+
':is(h1, h2, h3) .target',
42+
'.target:is(h1, h2, h3)',
4143
];
4244

43-
validSelectors.forEach((selector) =>
44-
it(selector, () => {
45-
expect(() => validateSelector(selector, 'target')).not.toThrow();
46-
}),
47-
);
45+
it.each(validSelectors)('%s', (selector) => {
46+
expect(() => validateSelector(selector, 'target')).not.toThrow();
47+
});
4848
});
4949

5050
describe('invalid selectors', () => {
@@ -69,12 +69,12 @@ describe('validateSelector', () => {
6969
':is(.target, .a, .target)',
7070
':where(.target, .target > span)',
7171
':is(.target, .target > span)',
72+
':where(.a, .b, .c)',
73+
':is(.a, .b, .c)',
7274
];
7375

74-
invalidSelectors.forEach((selector) =>
75-
it(selector, () => {
76-
expect(() => validateSelector(selector, 'target')).toThrow();
77-
}),
78-
);
76+
it.each(invalidSelectors)('%s', (selector) => {
77+
expect(() => validateSelector(selector, 'target')).toThrow();
78+
});
7979
});
8080
});

0 commit comments

Comments
 (0)