Skip to content

Commit

Permalink
test: add a test for custom engine that does not respect root (#4777)
Browse files Browse the repository at this point in the history
  • Loading branch information
dgozman authored Dec 19, 2020
1 parent 2e220df commit fc30c29
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions test/selectors-register.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,21 @@ it('should handle errors', async ({playwright, page}) => {
error = await playwright.selectors.register('css', createDummySelector).catch(e => e);
expect(error.message).toBe('"css" is a predefined selector engine');
});

it('should not rely on engines working from the root', async ({ playwright, page }) => {
const createValueEngine = () => ({
create(root, target) {
return undefined;
},
query(root, selector) {
return root && root.value.includes(selector) ? root : undefined;
},
queryAll(root, selector) {
return root && root.value.includes(selector) ? [root] : [];
},
});

await playwright.selectors.register('__value', createValueEngine);
await page.setContent(`<input id=input1 value=value1><input id=input2 value=value2>`);
expect(await page.$eval('input >> __value=value2', e => e.id)).toBe('input2');
});

0 comments on commit fc30c29

Please sign in to comment.