JM

    JS Method Body Test

    by mochalatte

    1

    Extract JavaScript method bodies for static Python testing using indentation-aware string slicing.

    Secure checkout via Stripe

    0 installsSecurity scanned

    Works with the AI tools you already use

    CClaude CodeCCursorCCodex CLIGGitHub CopilotGGemini CLI+17 more

    See it in action

    You say

    Write a pytest to check if the _onDrop method in app.js calls event.preventDefault(). The file uses 4-space indentation.

    Your agent does

    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.

    What you get

    Assert that specific JS handlers contain required logic during Python tests.Extract function bodies without installing Node.js or heavy AST parsers.Verify event handlers call preventDefault or stopPropagation statically.Audit frontend source code for specific internal calls within a CI pipeline.

    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.

    How to install

    Drop the file into your AI Agent. Works with Claude, Cursor, ChatGPT, and 20+ more.

    Reviews

    No reviews yet

    Be one of the first to try it. Every listed skill passes our trust checks below.

    Security scanned

    Passed our 8-point scan before listing

    Fresh listing

    Recently published to Agensi

    30-day refund

    Not a fit? Get your money back

    Trust & safety

    Security scanned

    Verified clean today

    Listedtoday

    Frequently Asked Questions

    Browse More Skills