MCPcopy Create free account
hub / github.com/getsentry/sentry-javascript / fixtureVitestSerializer

Function fixtureVitestSerializer

packages/angular/patch-vitest.ts:183–207  ·  view source on GitHub ↗

* Serialize Angular fixture for Vitest * * @param fixture Angular Fixture Component * @returns HTML Child Node

(fixture: any)

Source from the content-addressed store, hash-verified

181 * @returns HTML Child Node
182 */
183function 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

Callers 1

serializeFunction · 0.85

Calls 1

entriesMethod · 0.65

Tested by

no test coverage detected