@@ -8,6 +8,7 @@ import { logNgHTML } from './logNgHTML';
88import * as fixturePrettier from './prettiers/fixture/pretty-fixture' ;
99import * as debugElementPrettier from './prettiers/debugElement/pretty-debugElement' ;
1010import * as htmlElementPrettier from './prettiers/htmlElement/pretty-htmlelement' ;
11+ import * as prettierUtil from './prettiers/prettier-util' ;
1112
1213@Component ( {
1314 selector : 'lib-mock-component' ,
@@ -25,6 +26,7 @@ describe('LogNgHTML', () => {
2526 let component : MockComponent ;
2627 let fixture : ComponentFixture < MockComponent > ;
2728 const theme = THEMES . DRACULA ;
29+ const enableComments = true ;
2830
2931 beforeEach ( async ( ( ) => {
3032 TestBed . configureTestingModule ( {
@@ -40,9 +42,10 @@ describe('LogNgHTML', () => {
4042
4143 it ( 'should call prettyPrintFixture incase we provide a component fixture' , ( ) => {
4244 spyOn ( fixturePrettier , 'fixturePrettier' ) ;
43- logNgHTML < MockComponent > ( fixture , theme ) ;
45+ logNgHTML < MockComponent > ( fixture , enableComments , theme ) ;
4446 expect ( fixturePrettier . fixturePrettier ) . toHaveBeenCalledWith (
4547 fixture ,
48+ enableComments ,
4649 theme
4750 ) ;
4851 } ) ;
@@ -51,9 +54,10 @@ describe('LogNgHTML', () => {
5154 spyOn ( console , 'log' ) ;
5255 spyOn ( debugElementPrettier , 'prettyPrintDebugElements' ) ;
5356 const debugElements = fixture . debugElement . queryAll ( By . css ( 'li' ) ) ;
54- logNgHTML ( debugElements , theme ) ;
57+ logNgHTML ( debugElements , enableComments , theme ) ;
5558 expect ( debugElementPrettier . prettyPrintDebugElements ) . toHaveBeenCalledWith (
5659 debugElements ,
60+ enableComments ,
5761 theme
5862 ) ;
5963 } ) ;
@@ -64,19 +68,21 @@ describe('LogNgHTML', () => {
6468 const htmlElements = fixture . debugElement
6569 . queryAll ( By . css ( 'li' ) )
6670 . map ( ( debugElement : DebugElement ) => debugElement . nativeElement ) ;
67- logNgHTML ( htmlElements , theme ) ;
71+ logNgHTML ( htmlElements , enableComments , theme ) ;
6872 expect ( htmlElementPrettier . prettyPrintHtmlElements ) . toHaveBeenCalledWith (
6973 htmlElements ,
74+ enableComments ,
7075 theme
7176 ) ;
7277 } ) ;
7378
7479 it ( 'should call prettyPrintDebugElement in case we provide a debug element' , ( ) => {
7580 spyOn ( debugElementPrettier , 'prettyPrintDebugElement' ) ;
7681 const debugElement = fixture . debugElement . queryAll ( By . css ( 'li' ) ) [ 0 ] ;
77- logNgHTML ( debugElement , theme ) ;
82+ logNgHTML ( debugElement , enableComments , theme ) ;
7883 expect ( debugElementPrettier . prettyPrintDebugElement ) . toHaveBeenCalledWith (
7984 debugElement ,
85+ enableComments ,
8086 theme
8187 ) ;
8288 } ) ;
@@ -85,9 +91,10 @@ describe('LogNgHTML', () => {
8591 spyOn ( htmlElementPrettier , 'prettyPrintHtmlElement' ) ;
8692 const htmlElement = fixture . debugElement . queryAll ( By . css ( 'li' ) ) [ 0 ]
8793 . nativeElement ;
88- logNgHTML ( htmlElement , theme ) ;
94+ logNgHTML ( htmlElement , enableComments , theme ) ;
8995 expect ( htmlElementPrettier . prettyPrintHtmlElement ) . toHaveBeenCalledWith (
9096 htmlElement ,
97+ enableComments ,
9198 theme
9299 ) ;
93100 } ) ;
@@ -96,7 +103,22 @@ describe('LogNgHTML', () => {
96103 spyOn ( console , 'log' ) ;
97104 spyOn ( prettyHTMLLog , 'highlight' ) ;
98105 const htmlString = '<h1>Foo</h1>' ;
99- logNgHTML ( htmlString , theme ) ;
106+ logNgHTML ( htmlString , enableComments , theme ) ;
100107 expect ( prettyHTMLLog . highlight ) . toHaveBeenCalledWith ( htmlString , theme ) ;
101108 } ) ;
109+
110+ it ( 'should print a warning and remove the comments we pass in an unknown type and enableComments' , ( ) => {
111+ const htmlString = '<h1>Foo</h1><!--Some comment-->' ;
112+ const commentFreeHTMLString = '<h1>Foo</h1>' ;
113+ spyOn ( console , 'log' ) ;
114+ spyOn ( prettyHTMLLog , 'highlight' ) ;
115+ spyOn ( prettierUtil , 'removeComments' ) . and . returnValue (
116+ commentFreeHTMLString
117+ ) ;
118+ logNgHTML ( htmlString , false , theme ) ;
119+ expect ( prettyHTMLLog . highlight ) . toHaveBeenCalledWith (
120+ commentFreeHTMLString ,
121+ theme
122+ ) ;
123+ } ) ;
102124} ) ;
0 commit comments