- Home
- Skills
- Code Quality & Review
- JS Method Body Test
JS Method Body Test
Extract JavaScript method bodies for static Python testing using indentation-aware string slicing.
$5
Works with the AI Agents you already use
JS Method Body Test
Example session with this skill installed
Write a pytest to check if the _onDrop method in app.js calls event.preventDefault(). The file uses 4-space indentation.
- Read your context and instructions
- Compiled the js method body
Method: CSS Anchor Slicing
def test_onDrop_calls_preventDefault():
from pathlib import Path
js = Path("app.js").read_text(encoding="utf-8")
sig = "_onDrop(event)"
sig_idx = js.find(sig + " {")
body_start = sig_idx + len(sig) + 2
body = js[body_start:js.find("\n },\n", body_start)]
assert "event.preventDefault()" in body
Expected outcome: Pass if the call exists.
Why it works: Uses the \n },\n anchor to isolate the method body.
Connects securely to your tools. The creator never sees your data.
About this skill
The problem
Python developers need to verify JavaScript function internals in pytest suites without the overhead of a Node.js runtime or complex AST parsers. Conventional regex approaches frequently fail on nested objects, template strings, or HTML attributes containing method signatures.
What it does
- Extracts JavaScript or TypeScript method bodies using indentation-aware string slicing.
- Detects file indentation styles (2-space, 4-space, or tabs) to identify function boundaries accurately.
- Avoids false positives from method names appearing inside strings or comments.
- Handles nested object literals and if-blocks that typically break standard regex patterns.
- Generates self-contained pytest functions for static source code assertions.
Frameworks & tools
Python, pytest, JavaScript, TypeScript.
Why this beats prompting it yourself
Writing reliable code-slicing logic manually is error-prone due to edge cases like trailing commas and varied indentation styles. This skill provides a specialized, tested algorithm that handles these boundaries out of the box without requiring heavy external dependencies like Esprima or Acorn.
Use cases
- Verify that a specific JS event handler calls a required API like
setData. - Ensure a legacy JS file contains necessary cleanup logic in a specific method.
- Audit source code for the presence of specific keywords within a restricted function scope.
- Perform fast, static validation of frontend logic inside a backend CI pipeline.
Known limitations
Requires consistent indentation patterns to identify method boundaries. It will not work on minified code or files with inconsistent spacing.
Requires consistent code indentation. Does not support minified JavaScript. Fails if the exact method signature (including parameters) is not provided.
How to use
- 1
Connect your agent to the Agensi MCP
Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup
- 2
Sign in to Agensi
Your agent shows a sign-in link. Sign in and click Allow.
- 3
Ask for what you need
Your agent loads this skill and uses it on your task. It always asks before any payment.
Reviews
No reviews yet
Be one of the first to try it. Every listed skill goes through the trust checks below.
Security scanned
Checked by our 8-point scan before listing
Fresh listing
Recently published to Agensi
Money-back guarantee
Doesn't do what its page promises? You get your money back.
Trust & safety
Security scan
Security scan passed 3 months ago
Requires
Permissions
No special permissions declared or detected