|
| 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 | +}); |
0 commit comments