Skip to content

Commit 89fc9aa

Browse files
committed
chore(docs): document logNgHTML not a function
1 parent c4a206c commit 89fc9aa

File tree

1 file changed

+31
-15
lines changed

1 file changed

+31
-15
lines changed

README.md

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
- [Examples](#examples-1)
2020
- [Print Angular comments](#print-angular-comments)
2121
- [Change the theme](#change-the-theme)
22+
- [FAQ](#faq)
2223

2324
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
2425

@@ -27,8 +28,8 @@
2728
When debugging component tests, it’s often necessary to inspect the DOM. The most common approach to do so is by using the good old `console.log` which has some downsides.
2829
First of all, it’s annoying always to type
2930

30-
```
31-
fixture.debugElement.nativeElement.innerHTML
31+
```typescript
32+
fixture.debugElement.nativeElement.innerHTML;
3233
```
3334

3435
Moreover, the console.log statement doesn’t print the HTML in a very readable way. Therefore we still need to copy the string in a new HTML file and format it to be able to inspect it. Not with `@angular-extensions/pretty-html-log`
@@ -56,8 +57,8 @@ npm i -D @angular-extensions/pretty-html-log
5657
This module is best used with Angular and Jest. Create a
5758
`setupJest.ts` file in your `src` directory and add the following line **after your jest-preset-angular import. ⚠️ The order can matter**:
5859

59-
```
60-
import '@angular-extensions/pretty-html-log'
60+
```typescript
61+
import '@angular-extensions/pretty-html-log';
6162
```
6263

6364
This import adds a `logNgHTML` method to your console. You can then
@@ -88,10 +89,8 @@ The `console.logNgHTML()` method has the following signature:
8889

8990
In your test you can simply write the following line.
9091

91-
```
92-
console.logNgHTML(
93-
fixture.debugElement.query(By.css('mat-tab-body'))
94-
)
92+
```typescript
93+
console.logNgHTML(fixture.debugElement.query(By.css('mat-tab-body')));
9594
```
9695

9796
Which will print the following string to your console
@@ -106,25 +105,25 @@ Which will print the following string to your console
106105

107106
Log the content innerHTML of a fixture
108107

109-
```
108+
```typescript
110109
console.logNgHTML(fixture);
111110
```
112111

113112
of a debugElement (or multiple debugElements)
114113

115-
```
114+
```typescript
116115
console.logNgHTML(fixture.debugElement);
117116
```
118117

119118
of a nativeElement (or multiple nativeElements)
120119

121-
```
120+
```typescript
122121
console.logNgHTML(fixture.debugElement.nativeElement);
123122
```
124123

125124
or even a simple HTML string
126125

127-
```
126+
```typescript
128127
console.logNgHTML('<h1>Foo</h1>');
129128
```
130129

@@ -134,7 +133,7 @@ Angular adds some comments to our HTML file. Usually, when debugging our tests,
134133
are not printed by default. However, there are cases where you want to print those comments. To do so, you
135134
can pass `true` as an additional flag tot he `logNgHTML` method.
136135

137-
```
136+
```typescript
138137
console.logNgHTML(fixture, true);
139138
```
140139

@@ -144,8 +143,25 @@ console.logNgHTML(fixture, true);
144143
Currently, we support (DRACULA, VSCODE and MATERIAL). The themes can be importet from `pretty-html-log`, the
145144
base library `@angular-extensions/pretty-html-log` depends on.
146145

147-
```
148-
import {THEMES} from 'pretty-html-log';
146+
```typescript
147+
import { THEMES } from 'pretty-html-log';
149148

150149
console.logNgHTML(fixture, false, THEMES.VSCODE);
151150
```
151+
152+
# FAQ
153+
154+
I use the module but I don't get autocompletion when typing `console.logNgHTML`, furthermore I get the following error when I run my tests. `console.logNgHTML is not a function`. This is usually a sign that your `tsconfig.json` doesn't include the `setupJest.ts` file. Make sure that the `setupJest.ts` is included in your `tsconfig.json`.
155+
156+
```json
157+
{
158+
"extends": "../tsconfig.json",
159+
"compilerOptions": {
160+
"outDir": "./out-tsc/spec",
161+
"types": ["jest", "node"],
162+
"esModuleInterop": true
163+
},
164+
"files": ["polyfills.ts", "../jest.setup.ts"],
165+
"include": ["**/*.spec.ts", "**/*.d.ts"]
166+
}
167+
```

0 commit comments

Comments
 (0)