Skip to content

Commit

Permalink
Merge pull request #633 from derbyjs/test-render-options
Browse files Browse the repository at this point in the history
  • Loading branch information
craigbeck authored May 15, 2024
2 parents 4870a85 + f8b2c78 commit 6c636f0
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/test-utils/ComponentHarness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,18 @@ export interface RenderOptions {

export class PageForHarness extends PageForClient {
component?: Component;
fragment?: any;
html?: any;
fragment?: DocumentFragment;
html?: string;
}

interface PageRenderedHtml extends PageForHarness {
html: string;
fragment: undefined;
}

interface PageRenderedFragment extends PageForHarness {
html: undefined;
fragment: DocumentFragment;
}

const derby = new DerbyForClient();
Expand Down Expand Up @@ -158,10 +168,10 @@ export class ComponentHarness extends EventEmitter {
* @returns { Page & {html: string} } - a `Page` that has a `html` property with the rendered HTML
* string
*/
renderHtml(options) {
renderHtml(options?: RenderOptions): PageRenderedHtml {
return this._get(function(page) {
page.html = page.get('$harness');
}, options);
}, options) as PageRenderedHtml;
}

/**
Expand All @@ -171,10 +181,10 @@ export class ComponentHarness extends EventEmitter {
* @returns { Page & {fragment: DocumentFragment} } a `Page` that has a `fragment` property with the
* rendered `DocumentFragment`
*/
renderDom(options) {
renderDom(options?: RenderOptions): PageRenderedFragment {
return this._get(function(page) {
page.fragment = page.getFragment('$harness');
}, options);
}, options) as PageRenderedFragment;
}

attachTo(parentNode, node) {
Expand All @@ -189,7 +199,7 @@ export class ComponentHarness extends EventEmitter {
* @param {(page: PageForHarness) => void} render
* @param {RenderOptions} [options]
*/
_get(renderFn: (page: PageForHarness) => void, options?): PageForHarness {
_get(renderFn: (page: PageForHarness) => void, options?: RenderOptions): PageForHarness {
options = options || {};
const url = options.url || '';

Expand Down

0 comments on commit 6c636f0

Please sign in to comment.