assertionLine function ~ 71.4%

Last updated: 2026-03-01T23:25:47.084Z

Metrics

LOC: 36 Complexity: 25 Params: 1 Coverage: 71.4% (10/14 lines, 15x executed)

Signature

assertionLine(assertion: E2EAssertion): : string

Architecture violations

View all

  • [warning] max-cyclomatic-complexity: 'assertionLine' has cyclomatic complexity 25 (max 10)

Source Code

function assertionLine(assertion: E2EAssertion): string {
  switch (assertion.type) {
    case "url-changed":
      return `  await expect(page).not.toHaveURL('${escapeString(assertion.expected ?? "")}');`;
    case "url-contains":
      return `  await expect(page).toHaveURL(new RegExp('${escapeString(assertion.expected ?? "")}'));`;
    case "visible-text":
      return assertion.expected
        ? `  await expect(page.getByText('${escapeString(assertion.expected)}')).toBeVisible();`
        : `  // Expect visible validation feedback`;
    case "element-visible":
      return `  await expect(page.locator('${escapeString(assertion.selector ?? "")}')).toBeVisible();`;
    case "element-hidden":
      return `  await expect(page.locator('${escapeString(assertion.selector ?? "")}')).toBeHidden();`;
    case "toast-message":
      return `  await expect(page.locator('${escapeString(assertion.selector ?? "[role=\\'alert\\']")}')).toBeVisible();`;
    case "field-value":
      return `  await expect(page.locator('${escapeString(assertion.selector ?? "")}')).toHaveValue('${escapeString(assertion.expected ?? "")}');`;
    case "field-error":
      return `  await expect(page.locator('${escapeString(assertion.selector ?? "")}')).toBeVisible();`;
    case "redirect":
      return `  await expect(page).toHaveURL(new RegExp('${escapeString(assertion.expected ?? "")}'));`;
    case "response-ok": {
      const url = escapeString(assertion.selector ?? "");
      const status = assertion.expected ?? "200";
      const urlFragment = url.split("/").pop() ?? url;
      return [
        `  // HTTP response assertion: ${assertion.description ?? `${url} → ${status}`}`,
        `  // To assert strictly, add before the submit action:`,
        `  //   const responsePromise = page.waitForResponse(r => r.url().includes('${urlFragment}') && r.status() === ${status});`,
        `  //   const response = await responsePromise;`,
        `  //   expect(response.status()).toBe(${status});`,
      ].join("\n");
    }
  }
}

Dependencies (Outgoing)

graph LR assertionLine["assertionLine"] escapeString["escapeString"] assertionLine -->|calls| escapeString style assertionLine fill:#dbeafe,stroke:#2563eb,stroke-width:2px click assertionLine "0f28f576e085ec59.html" click escapeString "5c2f25e3b4548c2d.html"
TargetType
escapeString calls

Impact (Incoming)

graph LR assertionLine["assertionLine"] recordedStepLine["recordedStepLine"] recordedStepLine -->|calls| assertionLine recordedStepLine -->|calls| assertionLine recordedStepLine -->|calls| assertionLine style assertionLine fill:#dbeafe,stroke:#2563eb,stroke-width:2px click assertionLine "0f28f576e085ec59.html" click recordedStepLine "741f3e787c830c95.html"
SourceType
recordedStepLine calls
recordedStepLine calls
recordedStepLine calls