Skip to content

Commit 17f2b90

Browse files
committed
inegration test: add assert function
1 parent cc3af32 commit 17f2b90

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const assert = (condition, message) => {
2+
if (!condition) {
3+
throw new Error('Assert failed: ' + (message || ''));
4+
}
5+
};
6+
7+
8+
module.exports = assert;
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const assert = require("./assert.js")
2+
3+
4+
describe("assert()", () => {
5+
test("if passed", () => {
6+
expect(() => {
7+
assert(true);
8+
}).not.toThrow();
9+
});
10+
11+
test("if failed without msg", () => {
12+
expect(() => {
13+
assert(false);
14+
}).toThrow("Assert failed: ");
15+
});
16+
17+
test("if failed with msg", () => {
18+
expect(() => {
19+
assert(false, "err msg");
20+
}).toThrow("Assert failed: err msg");
21+
});
22+
});

0 commit comments

Comments
 (0)