Skip to content

Commit 3628633

Browse files
committed
test(prettyfixture): test pretty Html element
1 parent f050f8f commit 3628633

2 files changed

Lines changed: 60 additions & 1 deletion

File tree

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import * as prettyHTMLElement from './pretty-htmlelement';
2+
import { prettyPrintHtmlElement } from './pretty-htmlelement';
3+
import * as prettyHTMLLog from 'pretty-html-log';
4+
import { THEMES } from 'pretty-html-log';
5+
6+
describe('pretty HTML element', () => {
7+
it('should call prettyHtmlElement with the htmlElement and pass it to console.log', () => {
8+
console.log = jest.fn();
9+
const htmlElement = {} as HTMLElement;
10+
spyOn(prettyHTMLElement, 'prettyHtmlElement');
11+
prettyHTMLElement.prettyPrintHtmlElement(htmlElement, THEMES.DRACULA);
12+
13+
expect(console.log).toHaveBeenCalledWith(
14+
prettyPrintHtmlElement(htmlElement, THEMES.DRACULA)
15+
);
16+
});
17+
18+
it(`should call prettyHtmlelement with the htmlElement for each htmlElement. It should then
19+
pass the returned value to console.log
20+
for each `, () => {
21+
console.log = jest.fn();
22+
23+
const htmlElementOne = { innerText: 'HtmlElementOne' } as HTMLElement;
24+
const htmlElementTwo = { innerText: 'HtmlElementTwo' } as HTMLElement;
25+
const htmlElementThree = { innerText: 'HtmlElementThree' } as HTMLElement;
26+
27+
const htmlElements = [
28+
htmlElementOne,
29+
htmlElementTwo,
30+
htmlElementThree
31+
] as HTMLElement[];
32+
spyOn(prettyHTMLElement, 'prettyHtmlElement');
33+
prettyHTMLElement.prettyPrintHtmlElements(htmlElements, THEMES.DRACULA);
34+
35+
expect(console.log).toHaveBeenCalledWith(
36+
prettyPrintHtmlElement(htmlElementOne, THEMES.DRACULA)
37+
);
38+
expect(console.log).toHaveBeenCalledWith(
39+
prettyPrintHtmlElement(htmlElementTwo, THEMES.DRACULA)
40+
);
41+
expect(console.log).toHaveBeenCalledWith(
42+
prettyPrintHtmlElement(htmlElementThree, THEMES.DRACULA)
43+
);
44+
});
45+
46+
it('should call the highlight method with the innerHTML', () => {
47+
const innerHTML = '<h1>Foo</h1>';
48+
const htmlElement = {
49+
innerHTML
50+
} as HTMLElement;
51+
spyOn(prettyHTMLLog, 'highlight');
52+
53+
prettyHTMLElement.prettyHtmlElement(htmlElement, THEMES.DRACULA);
54+
expect(prettyHTMLLog.highlight).toHaveBeenCalledWith(
55+
innerHTML,
56+
THEMES.DRACULA
57+
);
58+
});
59+
});

projects/pretty-html-log/src/lib/pretty-htmlelement.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Theme } from 'pretty-html-log';
22
import { highlight } from 'pretty-html-log';
33

4-
export const prettyPrintHtmlEleemnt = (
4+
export const prettyPrintHtmlElement = (
55
htmlElement: HTMLElement,
66
theme?: Theme
77
): void => {

0 commit comments

Comments
 (0)