@gluonjs/test-utils


@gluonjs/test-utils / packages/test-utils/src/ssr / SsrFixture

Interface: SsrFixture

Properties

readonly head: string


html

readonly html: string


name

readonly name: string


response

readonly response: SsrRequestResult


router

readonly router: RouterSnapshot


state

readonly state: string


stateScript

readonly stateScript: string


store

readonly store: StoreSnapshot


styles

readonly styles: StyleManifest

Methods

contains()

contains(value): boolean

Parameters

value

string

Returns

boolean

Example

Inspect immutable server HTML, head carriers, serialized state, and the full public request result before hydration:

ts
import type { SsrRequestResult } from '@gluonjs/ssr';
import {
  activeSsrFixtureNames,
  assertNoSsrFixtureLeaks,
  cleanupSsrFixtures,
  hydrateSsrFixture,
  renderSsrFixture,
  type HydratedSsrFixture,
  type HydrateSsrFixtureOptions,
  type HydrationFixtureContext,
  type RenderSsrFixtureOptions,
  type SsrFixture,
} from '@gluonjs/test-utils/ssr';

async function verifyShopRequest(render: () => Promise<SsrRequestResult>) {
  const renderOptions = { name: 'shop-product' } satisfies RenderSsrFixtureOptions;
  const server: SsrFixture = await renderSsrFixture(render, renderOptions);
  const options = {
    hydrate: async (context: HydrationFixtureContext) => ({
      retained: context.container.querySelector('#product-title') !== null,
    }),
    dispose: () => undefined,
  } satisfies HydrateSsrFixtureOptions<{ retained: boolean }>;
  const fixture: HydratedSsrFixture<{ retained: boolean }> = await hydrateSsrFixture(server, options);
  console.log(server.contains('Orbit Lamp'), fixture.hydrated.retained, activeSsrFixtureNames());
  await fixture.cleanup();
  await cleanupSsrFixtures();
  assertNoSsrFixtureLeaks();
}
void verifyShopRequest;