UNPKG

riot-test-utils

Version:
81 lines (80 loc) 2.5 kB
import { TagInstance, TagInterface, TagOpts, TagRefs, NestedTags, ObservableCallback, TagMixin } from 'riot'; import { WeakWrapper } from './index'; /** * Wrapper of tag instance shallow-rendered. * * @see shallow */ export default class RiotWrapper<TOpts extends TagOpts = TagOpts, TRefs extends TagRefs = TagRefs, TTags extends NestedTags = NestedTags> implements TagInterface { private readonly tagInstance; /** * Constructor * * @param tagInstance - tag instance to wrap */ constructor(tagInstance: TagInstance); /** Get tag instance */ readonly instance: TagInstance; /** Get the root element */ readonly root: Element; /** * Get opts of the instance. * It is typically passed opts with "dataIs" property */ readonly opts: TOpts & { dataIs: string; }; /** Get refs of the instance */ readonly refs: TRefs; /** Get tags */ readonly tags: TTags; /** * Parent tag being always `null` * Not undefined but null(type definition of riot **is** wrong.) */ readonly parent: TagInstance | undefined; /** Update this tag and its children */ update<T extends {}>(data?: T): void; /** Is the tag mounted? */ readonly isMounted: boolean; /** Mount the tag */ mount(): void; /** Unmount the tag */ unmount(keepTheParent?: boolean): void; /** * Register callback. * * Note: `this` is unwrapped instance as well. */ on(event: string, callback: ObservableCallback): this; /** * Register callback once. * * Note: `this` is unwrapped instance as well. */ one(event: string, callback: ObservableCallback): this; /** * Execute callbacks */ trigger(event: string, ...args: any[]): this; /** * Unregister callback(s) */ off(event: string, callback?: ObservableCallback): this; /** Apply mixin */ mixin(mixin: string | TagMixin): void; /** Get outer-HTML string */ html(): string; /** Get internal text content */ text(): string | null; toJSON(): object | null; /** Find elements by selector under this node */ find(selector: string): WeakWrapper; /** * Simulate firing an event * * @param type event type * @param options options to override event object */ simulate<T extends {}>(type: string, options?: T): void; }