Skip to content

Commit

Permalink
chore: mount JSX only once in tests (#10758)
Browse files Browse the repository at this point in the history
In the previous solution, the mount function was executed twice because the invoke function runs once for each chainer it contains.
  • Loading branch information
nnaydenow authored Feb 3, 2025
1 parent 1b2cd71 commit 790ecc1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export interface MountUI5Options extends MountLitTemplateOptions {
ui5Configuration: object;
}
export type MountOptions = Partial<MountUI5Options>;
export declare function mount<T extends keyof HTMLElementTagNameMap = any>(component: JSX.Element, options?: MountOptions): Cypress.Chainable<JQuery<HTMLElementTagNameMap[T]>>;
export declare function mount(component: JSX.Element, options?: MountOptions): CypressChainable<JQuery<HTMLElement>>;
declare global {
namespace Cypress {
interface Chainable {
Expand Down
34 changes: 17 additions & 17 deletions packages/tools/components-package/cypress/support/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,23 @@ function mount(component, options = {}) {
applyConfiguration(options);

// Mount JSX Element
return cy.wrap({ preactMount })
.invoke("preactMount", component, container)
.then(() => {
cy.get(container)
.find("*")
.should($el => {
const shadowrootsExist = [...$el].every(el => {
if (el.tagName.includes("-") && el.shadowRoot) {
return el.shadowRoot.hasChildNodes();
}

return true;
})

expect(shadowrootsExist, "Custom elements with shadow DOM have content in their shadow DOM").to.be.true;
})
});
preactMount(component, container);

cy.get(container)
.find("*")
.should($el => {
const shadowrootsExist = [...$el].every(el => {
if (el.tagName.includes("-") && el.shadowRoot) {
return el.shadowRoot.hasChildNodes();
}

return true;
})

expect(shadowrootsExist, "Custom elements with shadow DOM have content in their shadow DOM").to.be.true;
})

return cy.get(container);
}

setupHooks(cleanup);
Expand Down

0 comments on commit 790ecc1

Please sign in to comment.