* Serialize Angular fixture for Vitest * * @param fixture Angular Fixture Component * @returns HTML Child Node
(fixture: any)
| 181 | * @returns HTML Child Node |
| 182 | */ |
| 183 | function fixtureVitestSerializer(fixture: any) { |
| 184 | // * Get Component meta data |
| 185 | const componentType = (fixture?.componentType ? fixture.componentType : fixture.componentRef.componentType) as any; |
| 186 | |
| 187 | let inputsData: string = ''; |
| 188 | |
| 189 | const selector = Reflect.getOwnPropertyDescriptor(componentType, '__annotations__')?.value[0].selector; |
| 190 | |
| 191 | if (componentType?.propDecorators) { |
| 192 | inputsData = Object.entries(componentType.propDecorators) |
| 193 | .map(([key, value]) => `${key}="${value}"`) |
| 194 | .join(''); |
| 195 | } |
| 196 | |
| 197 | // * Get DOM Elements |
| 198 | const divElement = fixture?.nativeElement ? fixture.nativeElement : fixture.location.nativeElement; |
| 199 | |
| 200 | // * Convert string data to HTML data |
| 201 | const doc = new DOMParser().parseFromString( |
| 202 | `<${selector} ${inputsData}>${divElement.innerHTML}</${selector}>`, |
| 203 | 'text/html', |
| 204 | ); |
| 205 | |
| 206 | return doc.body.childNodes[0]; |
| 207 | } |
| 208 | |
| 209 | /** |
| 210 | * bind describe method to wrap describe.each function |