test: add a test for custom engine that does not respect root (#4777)

This commit is contained in:
Dmitry Gozman 2020-12-19 12:21:20 -08:00 committed by GitHub
parent 2e220df7ac
commit fc30c29a19
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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');
});