fix(selectors): allow :scope with additional css (#11338)
This commit is contained in:
parent
4efb30999f
commit
359d523ec3
|
|
@ -202,6 +202,9 @@ export class SelectorEvaluatorImpl implements SelectorEvaluator {
|
|||
let firstIndex = -1;
|
||||
if (css !== undefined) {
|
||||
elements = this._queryCSS(context, css);
|
||||
const hasScopeClause = funcs.some(f => f.name === 'scope');
|
||||
if (hasScopeClause && context.scope.nodeType === 1 /* Node.ELEMENT_NODE */)
|
||||
elements.unshift(context.scope as Element);
|
||||
} else {
|
||||
firstIndex = funcs.findIndex(func => this._getEngine(func.name).query !== undefined);
|
||||
if (firstIndex === -1)
|
||||
|
|
|
|||
|
|
@ -383,6 +383,13 @@ it('should work with :scope', async ({ page, server }) => {
|
|||
expect(await scope.$$eval(`css=* > :scope`, els => els.length)).toBe(0);
|
||||
expect(await scope.$$eval(`css=* ~ :scope`, els => els.length)).toBe(0);
|
||||
}
|
||||
|
||||
await page.setContent(`<article><div class=target>hello<span></span></div></article>`);
|
||||
// 'scope' should allow additional native css modifiers
|
||||
expect(await page.$eval(`div >> :scope.target`, e => e.textContent)).toBe('hello');
|
||||
expect(await page.$eval(`div >> :scope:nth-child(1)`, e => e.textContent)).toBe('hello');
|
||||
expect(await page.$eval(`div >> :scope.target:has(span)`, e => e.textContent)).toBe('hello');
|
||||
expect(await page.$eval(`html:scope`, e => e.nodeName)).toBe('HTML');
|
||||
});
|
||||
|
||||
it('should absolutize relative selectors', async ({ page, server }) => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue