Skip to content

Commit 124db3b

Browse files
authored
Merge pull request #13 from vinhyan/add-tests
Add more test cases for `file.test.js`
2 parents 856de62 + feca97b commit 124db3b

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

test/file.test.js

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
1-
import { readFile, checkIfDirectory } from "../src/fileUtils";
1+
import { checkIfDirectory, readFile } from "../src/fileUtils";
22

33
describe("File Utility", () => {
4-
5-
test("Read File", () => {
6-
7-
readFile("./examples/test.txt").then((data) => {
8-
expect(data).toBe("Hello World");
9-
});
10-
4+
test("Read File", () => {
5+
readFile("./examples/test.txt").then((data) => {
6+
expect(data).toBe("Hello World");
117
});
8+
});
129

13-
test('should return true if the path is a directory', async () => {
14-
const result = await checkIfDirectory('./examples');
15-
expect(result).toBe(true);
10+
test("Read File Error, return null", () => {
11+
readFile("./examples/does-not-exist.txt").then((data) => {
12+
expect(data).toBe(null);
1613
});
14+
});
15+
16+
test("should return true if the path is a directory", async () => {
17+
const result = await checkIfDirectory("./examples");
18+
expect(result).toBe(true);
19+
});
1720

21+
test("should return false if the path is not a directory", async () => {
22+
const result = await checkIfDirectory("./examples/dummy-file.txt");
23+
expect(result).toBe(false);
24+
});
1825
});

0 commit comments

Comments
 (0)