Repository: mozilla/pdf.js
File: test/integration/accessibility_spec.mjs (JavaScript)

Code before:
    });

    it("must check that the MathML is correctly inserted", async () => {
      await Promise.all(
        pages.map(async ([browserName, page]) => {
          const isSanitizerSupported = await page.evaluate(() =>
            (() => {
              try {
                // eslint-disable-next-line no-undef
                return typeof Sanitizer !== "undefined";
              } catch {
                return false;
              }
            })()
          );
          if (isSanitizerSupported) {
            const mathML = await page.$eval(
              "span.structTree span[aria-owns='p58R_mc13'] > math",
              el => el?.innerHTML ?? ""
            );
            expect(mathML)
              .withContext(`In ${browserName}`)
              .toEqual(
                " <msqrt><msup><mi>x</mi><mn>2</mn></msup></msqrt> <mo>=</mo> <mrow><mo>|</mo><mi>x</mi><mo>|</mo></mrow> "
              );
          }
        })
      );
    });
  });

  describe("MathML tags in the struct tree", () => {
    let pages;

    beforeEach(async () => {
      pages = await loadAndWait("bug1937438_mml_from_latex.pdf", ".textLayer");
    });

    afterEach(async () => {
      await closePages(pages);
    });

    it("must check that the MathML is correctly inserted", async () => {
      await Promise.all(
        pages.map(async ([browserName, page]) => {
          const mathML = await page.$eval(
            "span.structTree span[role='group'] span[role='group']:last-child > span math",
            el => el?.innerHTML ?? ""
          );
          expect(mathML)
            .withContext(`In ${browserName}`)

Review comment (security):
I just realized: it would be good to have an `else` branch here with `pending("Sanitizer API is not supported")`. This way the test logs will explicitly flag the test as not having run instead of the test being marked as passed silently even though no assertions were actually made, which could prevent confusion.

Code after:
    });

    it("must check that the MathML is correctly inserted", async () => {
      await Promise.all(
        pages.map(async ([browserName, page]) => {
          const isSanitizerSupported = await page.evaluate(() => {
            try {
              // eslint-disable-next-line no-undef
              return typeof Sanitizer !== "undefined";
            } catch {
              return false;
            }
          });
          if (isSanitizerSupported) {
            const mathML = await page.$eval(
              "span.structTree span[aria-owns='p58R_mc13'] > math",
              el => el?.innerHTML ?? ""
            );
            expect(mathML)
              .withContext(`In ${browserName}`)
              .toEqual(
                " <msqrt><msup><mi>x</mi><mn>2</mn></msup></msqrt> <mo>=</mo> <mrow><mo>|</mo><mi>x</mi><mo>|</mo></mrow> "
              );
          } else {
            pending(`Sanitizer API (in ${browserName}) is not supported`);
          }
        })
      );
    });
  });

  describe("MathML tags in the struct tree", () => {
    let pages;

    beforeEach(async () => {
      pages = await loadAndWait("bug1937438_mml_from_latex.pdf", ".textLayer");
    });

    afterEach(async () => {
      await closePages(pages);
    });

    it("must check that the MathML is correctly inserted", async () => {
      await Promise.all(
        pages.map(async ([browserName, page]) => {
          const mathML = await page.$eval(
            "span.structTree span[role='group'] span[role='group']:last-child > span math",
            el => el?.innerHTML ?? ""
          );
          expect(mathML)
            .withContext(`In ${browserName}`)