Skip to content

Commit 017be1f

Browse files
committed
improve unit tests
1 parent 5d48d30 commit 017be1f

File tree

4 files changed

+30
-9
lines changed

4 files changed

+30
-9
lines changed

Diff for: test/unit/utils/UserFunction.test.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
"use strict";
44

55
require("should");
6+
import { HandlerNotFound } from "../../../src/Errors";
67
import { load } from "../../../src/utils/UserFunction";
78

89
describe("Invoking the load function", async() => {
9-
it("should not fail when init hook function is present", async() => {
10+
it("should resolve promise when init hook function is present", async() => {
1011
const handler = "InitPresent.handler"
1112
const appRoot = "test/unit/utils/function";
1213

@@ -16,9 +17,9 @@ describe("Invoking the load function", async() => {
1617
)) as Function;
1718

1819
handlerFunc.should.be.Function;
19-
handlerFunc.should.not.be.null;
20+
handlerFunc().should.be.true;
2021
});
21-
it("should not fail when init hook function is absent", async() => {
22+
it("should not resolve the promise when init hook function is absent", async() => {
2223
const handler = "InitAbsent.handler"
2324
const appRoot = "test/unit/utils/function";
2425

@@ -28,7 +29,7 @@ describe("Invoking the load function", async() => {
2829
)) as Function;
2930

3031
handlerFunc.should.be.Function;
31-
handlerFunc.should.not.be.null;
32+
handlerFunc().should.be.false;
3233
});
3334
it("should catch TypeError exception", async() => {
3435
const handler = "InitThrowsTypeError.handler"
@@ -40,6 +41,6 @@ describe("Invoking the load function", async() => {
4041
)) as Function;
4142

4243
handlerFunc.should.be.Function;
43-
handlerFunc.should.not.be.null;
44+
handlerFunc().should.be.true;
4445
});
4546
});

Diff for: test/unit/utils/function/InitAbsent.js

+22-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
1+
// console.log("******** enter the init block ********");
2+
3+
let resolved = "No";
4+
5+
function sleep(ms) {
6+
return new Promise((resolve) => setTimeout(resolve, ms)).then(() => {resolved = "Yes!"});
7+
}
8+
9+
async function init() {
10+
// console.log("******** enter initializeFunction hook ********");
11+
// console.log("******** Is promised resolved? " + resolved + " ********");
12+
// console.log("******** sleep for 20 ms... ********")
13+
let p = await sleep(20);
14+
// console.log("******** wake up ********");
15+
// console.log("******** Is promised resolved? " + resolved + " ********");
16+
}
17+
18+
init();
19+
120
exports.handler = async (event, context) => {
2-
return 'Function complete.';
21+
// console.log("******** enter the handler ********");
22+
// console.log("******** Is promised resolved? " + resolved + " ********");
23+
return ( resolved ? true: false );
324
}

Diff for: test/unit/utils/function/InitPresent.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,5 @@ exports.initializeFunction = async () => {
1818
exports.handler = async (event, context) => {
1919
// console.log("******** enter the handler ********");
2020
// console.log("******** Is promised resolved? " + resolved + " ********");
21-
22-
return 'Function complete.';
21+
return ( resolved ? true: false );
2322
}

Diff for: test/unit/utils/function/InitThrowsTypeError.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ exports.initializeFunction = async () => {
33
}
44

55
exports.handler = async (event, context) => {
6-
return 'Function complete.';
6+
return true;
77
}

0 commit comments

Comments
 (0)