assertionLine function ~ 71.4%

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

Metrics

LOC: 35 Complexity: 25 Params: 1 Coverage: 71.4% (10/14 lines, 14x 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 `    cy.url().should('not.eq', '${escapeString(assertion.expected ?? "")}');`;
    case "url-contains":
      return `    cy.url().should('include', '${escapeString(assertion.expected ?? "")}');`;
    case "visible-text":
      return assertion.expected
        ? `    cy.contains('${escapeString(assertion.expected)}').should('be.visible');`
        : `    // Expect visible validation feedback`;
    case "element-visible":
      return `    cy.get('${escapeString(assertion.selector ?? "")}').should('be.visible');`;
    case "element-hidden":
      return `    cy.get('${escapeString(assertion.selector ?? "")}').should('not.be.visible');`;
    case "toast-message":
      return `    cy.get('${escapeString(assertion.selector ?? "[role=\\'alert\\']")}').should('be.visible');`;
    case "field-value":
      return `    cy.get('${escapeString(assertion.selector ?? "")}').should('have.value', '${escapeString(assertion.expected ?? "")}');`;
    case "field-error":
      return `    cy.get('${escapeString(assertion.selector ?? "")}').should('be.visible');`;
    case "redirect":
      return `    cy.url().should('include', '${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:`,
        `    //   cy.intercept('*', '*${urlFragment}*').as('apiRequest');`,
        `    //   cy.wait('@apiRequest').its('response.statusCode').should('eq', ${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 "634ac9a3545ea033.html" click escapeString "5c2f25e3b4548c2d.html"
TargetType
escapeString calls

No incoming dependencies.