diff --git a/nodeunit/nodeunit-tests.ts b/nodeunit/nodeunit-tests.ts index bdd705b0e3..e7cf5e73e9 100644 --- a/nodeunit/nodeunit-tests.ts +++ b/nodeunit/nodeunit-tests.ts @@ -14,10 +14,10 @@ var block: () =>{ }; export var testGroup: nodeunit.ITestGroup = { - setUp: function (callback: nodeunit.ICallbackFunction) { + setUp: (callback) => { callback(); }, - tearDown: function (callback: nodeunit.ICallbackFunction) { + tearDown: (callback) => { callback(); }, test1: function (test: nodeunit.Test) { @@ -55,5 +55,83 @@ export var testGroup: nodeunit.ITestGroup = { test.done(error); test.done(); + }, + "This is a test with a nice description": (test: nodeunit.Test) => { + test.done(); } }; + + +// see https://github.com/caolan/nodeunit/blob/master/examples/nested/nested_reporter_test.unit.js for example. +// (https://github.com/caolan/nodeunit/commit/9fee91149324f79753eadbcf8993399a7d76da40) + + + +var testCase = nodeunit.testCase; + +export var testCaseGroup = testCase({ + "Test 0.1": function(test: nodeunit.Test) { + test.ok(true); + test.done(); + }, + + "TC 1": testCase({ + "TC 1.1": testCase({ + "Test 1.1.1": function(test: nodeunit.Test) { + test.ok(true); + test.done(); + } + }) + }), + + "TC 2": testCase({ + "TC 2.1": testCase({ + "TC 2.1.1": testCase({ + "Test 2.1.1.1": function(test: nodeunit.Test) { + test.ok(true); + test.done(); + }, + + "Test 2.1.1.2": function(test: nodeunit.Test) { + test.ok(true); + test.done(); + } + }), + + "TC 2.2.1": testCase({ + "Test 2.2.1.1": function(test: nodeunit.Test) { + test.ok(true); + test.done(); + }, + + "TC 2.2.1.1": testCase({ + "Test 2.2.1.1.1": function(test: nodeunit.Test) { + test.ok(true); + test.done(); + }, + }), + + "Test 2.2.1.2": function(test: nodeunit.Test) { + test.ok(true); + test.done(); + } + }) + }) + }), + + "TC 3": testCase({ + "TC 3.1": testCase({ + "TC 3.1.1": testCase({ + "Test 3.1.1.1 (should fail)": function(test: nodeunit.Test) { + test.ok(false); + test.done(); + } + }) + }) + }) +}); + + + + + diff --git a/nodeunit/nodeunit.d.ts b/nodeunit/nodeunit.d.ts index c427dbf171..2775ee23c5 100644 --- a/nodeunit/nodeunit.d.ts +++ b/nodeunit/nodeunit.d.ts @@ -6,6 +6,11 @@ // Imported from: https://github.com/soywiz/typescript-node-definitions/nodeunit.d.ts declare module 'nodeunit' { + export interface ITestCase { + (testCase: {[property: string]: ITestBody | ITestGroup | void}) : void; + } + export var testCase : ITestCase; + export interface Test { done: ICallbackFunction; expect(num: number): void; @@ -31,15 +36,15 @@ declare module 'nodeunit' { // Test Group Usage: // var testGroup: nodeunit.ITestGroup = { - // setUp: function (callback: nodeunit.ICallbackFunction): void { - // callback(); - // }, - // tearDown: function (callback: nodeunit.ICallbackFunction): void { - // callback(); - // }, - // test1: function (test: nodeunit.Test): void { - // test.done(); - // } + // setUp: (callback) => { + // callback(); + // }, + // tearDown: (callback) => { + // callback(); + // }, + // test1: (test: nodeunit.Test) => { + // test.done(); + // } // } // exports.testgroup = testGroup; @@ -48,12 +53,14 @@ declare module 'nodeunit' { } export interface ITestGroup { + /** The setUp function is run before each test */ setUp?: (callback: ICallbackFunction) => void; + /** The tearDown function is run after each test calls test.done() */ tearDown?: (callback: ICallbackFunction) => void; + [property: string] : ITestGroup | ITestBody | ((callback: ICallbackFunction) => void); } export interface ICallbackFunction { (err?: any): void; } } -