detectAssertions function exported ✓ 100.0%
Last updated: 2026-03-01T23:25:47.081Z
Metrics
LOC: 77
Complexity: 13
Params: 4
Coverage: 100.0% (20/20 lines, 11x executed)
Signature
detectAssertions(
actions: CapturedAction[],
pageUrl: string,
capturedResponses?: CapturedHttpResponse[],
): : E2EAssertion[]
Summary
Detects potential success assertions for a form submit. Analyzes the page for common patterns of success feedback and uses captured HTTP responses to generate response assertions.
Architecture violations
- [warning] max-cyclomatic-complexity: 'detectAssertions' has cyclomatic complexity 13 (max 10)
Source Code
export function detectAssertions(
actions: CapturedAction[],
pageUrl: string,
capturedResponses?: CapturedHttpResponse[],
): E2EAssertion[] {
const assertions: E2EAssertion[] = [];
// 1. If there's a submit action, expect URL might change
const hasSubmit = actions.some(
(a) => a.actionType === "click" || a.actionType === "submit",
);
if (hasSubmit) {
assertions.push({
type: "url-changed",
expected: pageUrl,
description: "URL should change after form submit",
});
}
// 2. Look for common success message containers
const successSelectors = [
".alert-success",
".toast-success",
".notification-success",
"[role='alert']",
".success-message",
".flash-success",
".Toastify__toast--success",
".ant-message-success",
".MuiAlert-standardSuccess",
];
for (const sel of successSelectors) {
if (document.querySelector(sel)) {
assertions.push({
type: "element-visible",
selector: sel,
description: `Success element "${sel}" should be visible`,
});
break; // One success assertion is enough
}
}
// 3. If form has action attribute with different URL, expect redirect
const forms = document.querySelectorAll("form[action]");
for (const form of forms) {
const action = form.getAttribute("action");
if (
action &&
action !== "#" &&
action !== "" &&
!action.startsWith("javascript:")
) {
assertions.push({
type: "redirect",
expected: action,
description: `Form should redirect to ${action}`,
});
break;
}
}
// 4. HTTP response assertions from captured AJAX/XHR requests
if (capturedResponses && capturedResponses.length > 0) {
for (const response of capturedResponses) {
assertions.push({
type: "response-ok",
selector: response.url,
expected: String(response.status),
description: `${response.method} ${response.url} should return ${response.status}`,
});
}
}
return assertions;
}
Dependencies (Outgoing)
| Target | Type |
|---|---|
| E2EAssertion | uses |
| CapturedAction | uses |
| CapturedHttpResponse | uses |
Impact (Incoming)
| Source | Type |
|---|---|
| FillableElement | uses |