Repository: puppeteer/puppeteer
File: test/src/waittask.spec.ts (TypeScript)

Code before:
      const {page, server} = await getTestState();

      await page.goto(server.EMPTY_PAGE);
      const frame = page.mainFrame();
      const watchdog = frame.waitForSelector('div');
      await frame.evaluate(addElement, 'br');
      await frame.evaluate(addElement, 'div');
      using eHandle = (await watchdog)!;
      const tagName = await (await eHandle.getProperty('tagName')).jsonValue();
      expect(tagName).toBe('DIV');
    });

    it('should work when node is added through innerHTML', async () => {
      const {page, server} = await getTestState();

      await page.goto(server.EMPTY_PAGE);
      const watchdog = page.waitForSelector('h3 div');
      await page.evaluate(addElement, 'span');
      await page.evaluate(() => {
        return (document.querySelector('span')!.innerHTML =
          '<h3><div></div></h3>');
      });
      await watchdog;
    });

    // MutationPoller currently does not support shadow DOM.
    it.skip('should work when node is added in a shadow root', async () => {
      const {page, server} = await getTestState();

      await page.goto(server.EMPTY_PAGE);
      const watcher = page.waitForSelector('div >>> h1');
      await page.evaluate(addElement, 'div');
      await expect(
        Promise.race([watcher, createTimeout(40)])
      ).resolves.toBeFalsy();
      await page.evaluate(() => {
        const host = document.querySelector('div')!;
        const shadow = host.attachShadow({mode: 'open'});
        const h1 = document.createElement('h1');
        h1.textContent = 'inside';
        shadow.appendChild(h1);
      });
      using element = await watcher;
      expect(
        await element!.evaluate(el => {
          return el.textContent;
        })
      ).toBe('inside');
    });

    it('should work for selector with a pseudo class', async () => {

Review comment (suggestion):
```suggestion
    // MutationPoller currently does not support shadow DOM.
    // See https://github.com/puppeteer/puppeteer/issues/13163.
```

Code after:
      const {page, server} = await getTestState();

      await page.goto(server.EMPTY_PAGE);
      const frame = page.mainFrame();
      const watchdog = frame.waitForSelector('div');
      await frame.evaluate(addElement, 'br');
      await frame.evaluate(addElement, 'div');
      using eHandle = (await watchdog)!;
      const tagName = await (await eHandle.getProperty('tagName')).jsonValue();
      expect(tagName).toBe('DIV');
    });

    it('should work when node is added through innerHTML', async () => {
      const {page, server} = await getTestState();

      await page.goto(server.EMPTY_PAGE);
      const watchdog = page.waitForSelector('h3 div');
      await page.evaluate(addElement, 'span');
      await page.evaluate(() => {
        return (document.querySelector('span')!.innerHTML =
          '<h3><div></div></h3>');
      });
      await watchdog;
    });

    // MutationPoller currently does not support shadow DOM.
    // See https://github.com/puppeteer/puppeteer/issues/13163.
    it.skip('should work when node is added in a shadow root', async () => {
      const {page, server} = await getTestState();

      await page.goto(server.EMPTY_PAGE);
      const watcher = page.waitForSelector('div >>> h1');
      await page.evaluate(addElement, 'div');
      await expect(
        Promise.race([watcher, createTimeout(40)])
      ).resolves.toBeFalsy();
      await page.evaluate(() => {
        const host = document.querySelector('div')!;
        const shadow = host.attachShadow({mode: 'open'});
        const h1 = document.createElement('h1');
        h1.textContent = 'inside';
        shadow.appendChild(h1);
      });
      using element = await watcher;
      expect(
        await element!.evaluate(el => {
          return el.textContent;
        })
      ).toBe('inside');
    });