Skip to content

Commit 81c665a

Browse files
committed
added import node test and assert
1 parent 48c4ca2 commit 81c665a

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

‎practice-tdd/repeat-str.test.js‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
// Implement a function repeatStr
2+
import { test } from "node:test";
3+
import { strict as assert } from "node:assert";
24
import { repeatStr } from "./repeat-str.js";
35
// Given a target string `str` and a positive integer `count`,
46
// When the repeatStr function is called with these inputs,
@@ -13,7 +15,7 @@ test("should repeat the string count times", () => {
1315
const str = "hello";
1416
const count = 3;
1517
const repeatedStr = repeatStr(str, count);
16-
expect(repeatedStr).toEqual("hellohellohello");
18+
assert.equal(repeatedStr, "hellohellohello");
1719
});
1820

1921
// Case: handle count of 1:
@@ -25,7 +27,7 @@ test("should return the original string when count is 1", () => {
2527
const str = "hello";
2628
const count = 1;
2729
const repeatedStr = repeatStr(str, count);
28-
expect(repeatedStr).toEqual("hello");
30+
assert.equal(repeatedStr, "hello");
2931
});
3032

3133
// Case: Handle count of 0:
@@ -37,7 +39,7 @@ test("should return an empty string when count is 0", () => {
3739
const str = "hello";
3840
const count = 0;
3941
const repeatedStr = repeatStr(str, count);
40-
expect(repeatedStr).toEqual("");
42+
assert.equal(repeatedStr, "");
4143
});
4244

4345
// Case: Handle negative count:
@@ -49,5 +51,7 @@ test("should throw an error when count is negative", () => {
4951
const str = "hello";
5052
const count = -1;
5153

52-
expect(() => repeatStr(str, count)).toThrow();
54+
assert.throws(() => {
55+
repeatStr(str, count);
56+
});
5357
});

0 commit comments

Comments
 (0)