API › @qwik.dev/qwik/testing

child

child: HTMLElement;

createDocument

Create emulated Document for server environment. Does not implement the full browser document and window API. This api may be removed in the future.

export declare function createDocument(opts?: MockDocumentOptions): Document;

Parameter

Type

Description

opts

MockDocumentOptions

(Optional)

Returns:

Document

Edit this section

createDOM

CreatePlatform and CreateDocument

createDOM: (input?: { html?: string }) =>
  Promise<{
    render: (
      jsxElement: JSXOutput,
    ) => Promise<import("@qwik.dev/core").RenderResult>;
    screen: HTMLElement;
    userEvent: (
      queryOrElement: string | Element | keyof HTMLElementTagNameMap | null,
      eventNameCamel: string | keyof WindowEventMap,
      eventPayload?: any,
    ) => Promise<Event | null>;
  }>;

Parameter

Type

Description

{ html }

(not declared)

(Optional)

input

{ html?: string; }

(Optional)

Returns:

Promise<{ render: (jsxElement: JSXOutput) => Promise<import("@qwik.dev/core").RenderResult>; screen: HTMLElement; userEvent: (queryOrElement: string | Element | keyof HTMLElementTagNameMap | null, eventNameCamel: string | keyof WindowEventMap, eventPayload?: any) => Promise<Event | null>; }>

Edit this section

document

document: MockDocument;

domRender

export declare function domRender(
  jsx: JSXOutput,
  opts?: {
    debug?: boolean;
  },
): Promise<{
  document: Document;
  container: import("@qwik.dev/core").ClientContainer;
  vNode: _VNode | null;
  getStyles: () => Record<string, string | string[]>;
}>;

Parameter

Type

Description

jsx

JSXOutput

opts

{ debug?: boolean; }

(Optional)

Returns:

Promise<{ document: Document; container: import("@qwik.dev/core").ClientContainer; vNode: _VNode | null; getStyles: () => Record<string, string | string[]>; }>

Edit this section

ElementFixture

Creates a simple DOM structure for testing components.

By default EntityFixture creates:

<host q:view="./component_fixture.noop">
  <child></child>
</host>
export declare class ElementFixture

Constructor

Modifiers

Description

(constructor)(options)

Constructs a new instance of the ElementFixture class

Property

Modifiers

Type

Description

child

HTMLElement

document

MockDocument

host

HTMLElement

parent

HTMLElement

superParent

HTMLElement

window

MockWindow

Edit this section

emulateExecutionOfQwikFuncs

export declare function emulateExecutionOfQwikFuncs(document: Document): void;

Parameter

Type

Description

document

Document

Returns:

void

Edit this section

expectDOM

export declare function expectDOM(
  actual: Element,
  expected: string,
): Promise<void>;

Parameter

Type

Description

actual

Element

expected

string

Returns:

Promise<void>

Edit this section

getTestPlatform

export declare function getTestPlatform(): TestPlatform;

Returns:

TestPlatform

Edit this section

host

host: HTMLElement;

InOrderAuto

export interface InOrderAuto

Property

Modifiers

Type

Description

maximumChunk?

number

(Optional)

maximumInitialChunk?

number

(Optional)

strategy

'auto'

Edit this section

InOrderDirect

export interface InOrderDirect

Property

Modifiers

Type

Description

strategy

'direct'

Edit this section

InOrderDisabled

export interface InOrderDisabled

Property

Modifiers

Type

Description

strategy

'disabled'

Edit this section

InOrderStreaming

export type InOrderStreaming = InOrderAuto | InOrderDisabled | InOrderDirect;

References: InOrderAuto, InOrderDisabled, InOrderDirect

Edit this section

OutOfOrderStreaming

export type OutOfOrderStreaming = boolean;

Edit this section

parent

parent: HTMLElement;

ssrRenderToDom

export declare function ssrRenderToDom(
  jsx: JSXOutput,
  opts?: {
    debug?: boolean;
    raw?: boolean;
    qwikLoader?: boolean;
    containerTagName?: string;
    stream?: StreamWriter;
    streaming?: StreamingOptions;
    resume?: boolean;
    onBeforeResume?: (document: Document) => void;
  },
): Promise<{
  container: _DomContainer;
  document: Document;
  vNode: _VNode | null;
  getStyles: () => Record<string, string | string[]>;
}>;

Parameter

Type

Description

jsx

JSXOutput

opts

{ debug?: boolean; raw?: boolean; qwikLoader?: boolean; containerTagName?: string; stream?: StreamWriter; streaming?: StreamingOptions; resume?: boolean; onBeforeResume?: (document: Document) => void; }

(Optional)

Returns:

Promise<{ container: _DomContainer; document: Document; vNode: _VNode | null; getStyles: () => Record<string, string | string[]>; }>

Edit this section

StreamingOptions

export interface StreamingOptions

Property

Modifiers

Type

Description

inOrder?

InOrderStreaming

(Optional)

outOfOrder?

OutOfOrderStreaming

(Optional)

Edit this section

superParent

superParent: HTMLElement;

trigger

Trigger an event in unit tests on an element. Needs to be kept in sync with the Qwik Loader event dispatching.

Events can be either case sensitive element-scoped events or scoped kebab-case.

Future deprecation candidate.

export declare function trigger(
  root: Element,
  queryOrElement: string | Element | keyof HTMLElementTagNameMap | null,
  eventName: string,
  eventPayload?: any,
  options?: {
    waitForIdle?: boolean;
  },
): Promise<Event | null>;

Parameter

Type

Description

root

Element

queryOrElement

string | Element | keyof HTMLElementTagNameMap | null

eventName

string

eventPayload

any

(Optional)

options

{ waitForIdle?: boolean; }

(Optional)

Returns:

Promise<Event | null>

Edit this section

vnode_fromJSX

export declare function vnode_fromJSX(jsx: JSXOutput): {
  vParent: _VirtualVNode | _ElementVNode;
  vNode: _VNode | null;
  document: _QDocument;
  container: ClientContainer;
};

Parameter

Type

Description

jsx

JSXOutput

Returns:

{ vParent: _VirtualVNode | _ElementVNode; vNode: _VNode | null; document: _QDocument; container: ClientContainer; }

Edit this section

waitForDrain

Wait for the scheduler to drain.

This is useful when testing async code.

export declare function waitForDrain(container: Container): Promise<void>;

Parameter

Type

Description

container

Container

The application container.

Returns:

Promise<void>

Edit this section

walkJSX

export declare function walkJSX(
  jsx: JSXOutput,
  apply: {
    enter: (jsx: JSXNodeInternal) => void;
    leave: (jsx: JSXNodeInternal) => void;
    text: (text: _Stringifiable) => void;
  },
): void;

Parameter

Type

Description

jsx

JSXOutput

apply

{ enter: (jsx: JSXNodeInternal) => void; leave: (jsx: JSXNodeInternal) => void; text: (text: _Stringifiable) => void; }

Returns:

void

Edit this section

window

window: MockWindow;