JSXでユニットテスト

てかまあ、lib/common/test-case.jsxの上の方に書いてあるんだけど。

// test.jsx

// TestCaseを継承する必要があるのでtest-case.jsxをインポート
import 'test-case.jsx';
import 'timer.jsx';

// _Testクラスという名前が重要
// TestCaseを継承する
final class _Test extends TestCase {

  // メソッド名はtestから始める
  function testAaa(): void {
    this.expect(1, '1 == 1').toBe(1);
    this.expect(1, '1 != 2').notToBe(2);
    this.expect(1, '1 < 2').toBeLT(2);
    this.expect(1, '1 <= 1').toBeLE(1);
    this.expect(2, '2 > 1').toBeGT(1);
    this.expect(2, '2 >= 2').toBeGE(2);
  }

  function testBbb(): void {

    // 非同期なメソッドなどの確認
    this.async(function (async: AsyncContext): void {
      Timer.setTimeout(function (): void {
        this.expect(1).toBe(1);
        async.done();
      }, 300);
    }, 1000);

  } 
}


あとは以下を実行すると結果が一緒にでてきます。色が付いてると良いんだけどなあ……

$ jsx --test test.jsx
1..2
        ok 1 - 1 == 1
        ok 2 - 1 != 2
        ok 3 - 1 < 2
        ok 4 - 1 <= 1
        ok 5 - 2 > 1
        ok 6 - 2 >= 2
        1..6
ok 1 - testAaa
        ok 1
        1..1
ok 2 - testBbb