summaryrefslogtreecommitdiffstats
path: root/devtools/client/webconsole/test/browser/browser_jsterm_error_docs.js
blob: 0e37ad27fb3f4f8faf50c639597f2d47de0cd2c2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

const TEST_URI = "data:text/html,<!DOCTYPE html>Test error documentation";

add_task(async function () {
  const hud = await openNewTabAndConsole(TEST_URI);

  // Check that errors with entries in errordocs.js display links next to their messages.
  const ErrorDocs = require("resource://devtools/server/actors/errordocs.js");

  const ErrorDocStatements = {
    JSMSG_BAD_RADIX: "(42).toString(0);",
    JSMSG_BAD_ARRAY_LENGTH: "([]).length = -1",
    JSMSG_NEGATIVE_REPETITION_COUNT: "'abc'.repeat(-1);",
    JSMSG_PRECISION_RANGE: "77.1234.toExponential(-1);",
  };

  for (const [errorMessageName, expression] of Object.entries(
    ErrorDocStatements
  )) {
    const errorUrl = ErrorDocs.GetURL({ errorMessageName });
    const title = errorUrl.split("?")[0];

    await clearOutput(hud);

    const { node } = await executeAndWaitForErrorMessage(
      hud,
      expression,
      "RangeError:"
    );
    const learnMoreLink = node.querySelector(".learn-more-link");
    ok(
      learnMoreLink,
      `There is a [Learn More] link for "${errorMessageName}" error`
    );
    is(
      learnMoreLink.title,
      title,
      `The link has the expected "${title}" title`
    );
    is(
      learnMoreLink.href,
      errorUrl,
      `The link has the expected "${errorUrl}" href value`
    );
  }
});