lib/common/test-case.jsx

Unit Test Framework for JSX

SYNOPSIS


import "test-case.jsx";
import "timer.jsx";

class _Test extends TestCase {

  // synchrounous tests which run in serial

  function testClearTimeout() : void {
    var id = Timer.setTimeout(() -> {
      this.fail("setTimeout called after clearTimeout");
    }, 1);
    Timer.clearTimeout(id);

    this.expect(id, "clearTimeout").toBe(id);
  }

  // asynchronous tests which start in parallel but run in serial

  function testSetTimeout() : void {
    this.async((async) -> {
      var to = 200;
      var t0 = Date.now();
      Timer.setTimeout(() -> {
        var t1 = Date.now();

        this.expect(t1 - t0, "setTimeout 200 ms.").toBeGE(to - 50);

        async.done();
      }, to);
    }, 1000);
  }
}

class TestCase

Base class for test cases

class TestCase.Matcher

Assertion Matcher, created by TestCase#expect()

function toBe(x : variant) : void

function notToBe(x : variant) : void

function toBeLT(x : number) : void

function toBeLE(x : number) : void

function toBeGT(x : number) : void

function toBeGE(x : number) : void

function toMatch(x : RegExp) : void

function notToMatch(x : RegExp) : void

var verbose : boolean

var showStackTrace : boolean

new TestCase()

function setUp() : void

Set up for each test method.

function tearDown() : void

Tear down for each test method.

function setUp(async : AsyncContext) : void

Set up for each asynchronous test method.

function tearDown(async : AsyncContext) : void

Tear down for each asynchronous test method.

__export__ function beforeClass(tests : Array.<string>) : void

__export__ function afterClass() : void

__export__ function run(name : string, testFunction : function () : void) : void

function after(name : string) : void

function finish() : void

function async(testBody : function (:AsyncContext) : void, timeoutHandler : function (:AsyncContext) : void, timeoutMS : int) : void

Prepares an asynchronous test block with a timeout handler.

function async(testBody : function (:AsyncContext) : void, timeoutMS : int) : void

Prepares an asynchronous test block. Automatically call this.fail() on timeout.

function pass(reason : string) : void

Tells a test passes.

function fail(reason : string) : void

Tells a test fails.

function equals(a : variant, b : variant) : boolean

function difflet(a : Array.<variant>, b : Array.<variant>) : string

function diag(message : string) : void

Shows diagnostic messages.

function note(message : string) : void

Shows notes on verbose mode.

override function toString() : string

class AsyncContext

new AsyncContext(test : TestCase, name : string, timeoutHandler : function (:AsyncContext) : void, timeoutMS : int)

function name() : string

The name of the running test method, e.g. "testAsyncFoo".

function done() : void