Skip to content

Commit

Permalink
make changes based on code review
Browse files Browse the repository at this point in the history
  • Loading branch information
crookse committed Jun 22, 2020
1 parent 45b08bf commit 5555752
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
15 changes: 8 additions & 7 deletions src/test_case.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
const encoder = new TextEncoder();
import { ITestPlan, ITestCase } from "./interfaces.ts";

/**
* A class to help create uniform test case objects.
*/
export class TestCase {
protected plan: any; // TODO(ebebbington) Use Plan interface
protected plan: ITestPlan;

constructor(plan: any) { // TODO(ebebbington) Use Plan interface
constructor(plan: ITestPlan) {
this.plan = plan;
}

Expand All @@ -16,7 +17,7 @@ export class TestCase {
}
Object.keys(this.plan.suites).forEach((suiteName) => {
// Run cases
this.plan.suites[suiteName].cases.forEach(async (c: any) => {
this.plan!.suites[suiteName].cases!.forEach(async (c: ITestCase) => {
// Run the case - required to run like this because the
// hooks need to be ran inside the Deno.test call. Deno.test seems to queue
// the tests, meaning all hooks are ran, and **then** the tests are ran
Expand All @@ -28,17 +29,17 @@ export class TestCase {
this.plan.before_each_suite_hook();
}
if (this.plan.suites[suiteName].before_all_case_hook) {
this.plan.suites[suiteName].before_all_case_hook();
this.plan.suites[suiteName].before_all_case_hook!();
}
if (this.plan.suites[suiteName].before_each_case_hook) {
this.plan.suites[suiteName].before_each_case_hook();
this.plan.suites[suiteName].before_each_case_hook!();
}
await c.testFn();
if (this.plan.suites[suiteName].after_each_case_hook) {
this.plan.suites[suiteName].after_each_case_hook();
this.plan.suites[suiteName].after_each_case_hook!();
}
if (this.plan.suites[suiteName].after_all_case_hook) {
this.plan.suites[suiteName].after_all_case_hook();
this.plan.suites[suiteName].after_all_case_hook!();
}
if (this.plan.after_each_suite_hook) {
this.plan.after_each_suite_hook();
Expand Down
23 changes: 13 additions & 10 deletions tests/unit/test_case_test.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
import { asserts } from "../../deps.ts";
import { TestCase } from "../../src/test_case.ts";
import { ITestPlan } from "../../src/interfaces.ts";

Deno.test({
name: "Unit | TestCase | run() | Runs the test without failing",
async fn(): Promise<void> {
const plan = {
"suite_1": {
cases: [{
name: "case_1",
new_name: "123 case_1",
testFn: function () {
asserts.assertEquals(true, true);
},
}],
},
const plan: ITestPlan = {
suites: {
"suite_1": {
cases: [{
name: "case_1",
new_name: "123 case_1",
testFn: function () {
asserts.assertEquals(true, true);
},
}],
},
}
};
const testCase = new TestCase(plan);
await testCase.run();
Expand Down

0 comments on commit 5555752

Please sign in to comment.