Format Code Now
/
Web & markupJavaScript Tester Next: Marquee Generator ›

JavaScript Tester

WM-138

Paste the code you want to check, then write one assertion per line, such as add(2, 3) ==> 5. Each line shows Pass or Fail, and a failure shows what came back.

Runs in your browser. Nothing is uploaded.

Code under test

Assertions

One per line: expression ==> expected

Ctrl+Enter (Cmd+Enter on a Mac) runs the code.

Results

    Console

    1. Press Run tests to check each assertion.

    How to use it

    1. Paste your function or module code in the Code under test box.
    2. In the Assertions box, write one check per line: expression ==> expected value.
    3. For a yes or no check, write just the expression, such as Array.isArray(result).
    4. Press Run tests or Ctrl+Enter and read the pass and fail list.
    5. Fix the code or the expectation and run again.

    How an assertion is written

    Each non-empty line is one assertion. Put the expression on the left, then ==>, then the value you expect, written as JavaScript: a number, a quoted string, an array, an object or another call. Lines starting with // are skipped. A line without ==> passes when its value is truthy. If an expression returns a promise, the tester waits up to 3 seconds for it to settle. An expression that throws is reported as a failure with the error message.

    What equal means here

    Both sides are compared with a strict deep check. The number 1 and the string "1" are different. Arrays need the same items in the same order; objects need the same own keys with equal values, in any key order. Maps, Sets, Dates and regular expressions are compared by content. NaN equals NaN and 0 equals -0. Floating point is not rounded, so 0.1 + 0.2 does not equal 0.3, which the sample shows on purpose.

    How it differs from the playground

    The JavaScript Playground on this site is for running code and reading console output. This tester runs your code first and then each assertion, and reports a pass or fail list with a count. Both use the same sandbox: a frame with scripts allowed and no origin, so the code cannot reach this page or the network. It is a quick checker, not a test framework: there are no describe blocks, setup hooks, mocks or coverage.

    Error messages and what to do

    MessageWhat it meansFix
    Add at least one assertion, such as add(2, 3) ==> 5.The Assertions box is empty or holds only comments.Write one check per line with ==> between the expression and the expected value.
    There are 301 assertions. The limit is 300.The Assertions box has more than 300 checks.Split them into two runs.

    Questions people ask

    How do I test a JavaScript function online?

    Paste the function into the Code under test box, then write lines such as add(2, 3) ==> 5 in the Assertions box and press Run tests. Each line shows Pass or Fail, and failures show the expected and actual values side by side.

    Why does 0.1 + 0.2 ==> 0.3 fail?

    JavaScript numbers are binary floating point, so 0.1 + 0.2 gives 0.30000000000000004. The tester compares exactly and does not round. Compare a rounded value instead, for example Math.round((0.1 + 0.2) * 100) / 100 ==> 0.3.

    Can I compare arrays and objects?

    Yes. Write the expected array or object after ==>, for example chunk([1, 2, 3], 2) ==> [[1, 2], [3]]. The comparison is deep and strict: same types, same items in order for arrays, and the same keys and values for objects.

    Can I test async functions?

    Yes. If the expression returns a promise, the tester waits for it, up to 3 seconds, and compares the resolved value. A rejected promise counts as a failure and shows the error. Timers and loops inside your code still run in the sandbox.

    How do I check that a function throws?

    There is no special syntax for that. Wrap the call in a small function that returns true when it throws, for example (() => { try { parse(''); return false; } catch { return true; } })(), and put it on its own line.

    Does the tester send my code anywhere?

    No. The code and assertions run in a sandboxed frame in your browser with network requests blocked. The last code you typed is kept in this browser so a refresh does not lose it, and nothing is uploaded.

    About this tool

    Each line of the assertions box is one check. "expression ==> expected" passes when both sides are deeply and strictly equal: same types, same array items in order, same object keys and values, with NaN equal to NaN and 0 equal to -0. A line without ==> passes when the expression is truthy. Promises are awaited for up to 3 seconds. The code runs first, then each assertion, all inside a sandboxed frame with its own blank origin and no network access. It is not a test framework: there are no describe blocks, mocks or spies, and an assertion cannot span several lines.

    Format Code Now: free, no ads, no accounts. Your input stays in your browser.