Adding tests should be extremely easy. Otherwise you’ll just skip it.

x9 provides three ways of creating tests:

Mini Tests (or Test Blocks)

If you use expect within a playground, it becomes a test. You’ll see its color change in the IDE.

function sum(a, b) {
  return a + b;
}

{
  expect(sum(1, 2)).toBe(3);
}

Async/Await

You can use await at the top level (within the block). The containing block will be automatically treated as an async function

{  expect(await sum(1, 2)).toBe(3);}

Proposal: Terse Assertion Syntax

Experimental: When using the Block form you also get some syntactic sugar.

{  // x9.test  sum(1, 2) === 3; // expect(1,2).toBe(3)  sum(1, 2) < 10; // expect(1,2).toBeLessThan(10)}

The goal of this syntax is twofold:

  1. It makes writing basic tests even easier (the ultimate goal is to remove all boundaries so writing basic tests becomes part of your normal workflow, with zero overhad)
  2. This terse syntax results in highly readable tests that can serve as documentation. For a related idea, see Python doctests

Notes: