Fleshed out some other ways to write tests with Nodeunit.

This commit is contained in:
Steve Ognibene
2015-08-12 16:27:16 -04:00
parent da995655d8
commit d202e275b2
2 changed files with 97 additions and 12 deletions
+80 -2
View File
@@ -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();
}
})
})
})
});
+17 -10
View File
@@ -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;
}
}