-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.test.js
43 lines (36 loc) · 1.06 KB
/
index.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
const parser = require("./index");
describe("parseHTML", () => {
it("should parse HTML string to an object", () => {
const htmlString =
'<div style="background-color: yellow;">Hello, world!</div>';
const parsedObject = parser.parseHTML(htmlString);
const expectedResult = {
tag: "div",
style: {
"background-color": "yellow",
},
text: "Hello, world!",
};
expect(parsedObject).toEqual(expectedResult);
});
});
jest.mock("fs");
const fs = require("fs");
describe("main", () => {
it("should read an HTML file and parse it", () => {
const mockHtmlContent = "<div>Hello, world!</div>";
const mockParsedObject = {
tag: "div",
text: "Hello, world!",
};
fs.readFile.mockImplementation((filePath, encoding, callback) => {
callback(null, mockHtmlContent);
});
const consoleLogSpy = jest.spyOn(console, "log");
process.argv = ["node", "index.js", "markup.html"];
parser();
expect(consoleLogSpy).toHaveBeenCalledWith(
JSON.stringify(mockParsedObject)
);
});
});