redfox-mx / cypress-lit

Browser-based Component Testing for Lit with Cypress.io 💙
MIT License
7 stars 1 forks source link

Improve mount function type #60

Open nnaydenow opened 5 days ago

nnaydenow commented 5 days ago

Hi,

Could you please enhance the template parameter description of mount command to have specific type instead of unknown?

Isn't it more correct to specific it as HTMLTemplateResult | string ?

Other possible solution for us is to provide export template result type into separate type which we can override.

Thanks!

redfox-mx commented 5 days ago

Hi @nnaydenow nice to meet you. Thank you for your PR 🚀

Hummm interesting 🤔. Is there some issue with unknown type?

I put unknown type since that's what lit render function does https://github.com/lit/lit/blob/1eb179f69d663440fd2ebd3589b6f2808d87494f/packages/lit-html/src/lit-html.ts#L2233

It was changed because lit cannot only render HTMLTemplateResult (and I add support for string). For example, you can pass a HTMLElement to it

cy.mount(MyCustomElement);
// behind the scenes 
render(MyCustomElement)

It's the same for arrays, arrays of elements, numbers, and other custom tagged templates.

nnaydenow commented 2 days ago

Hi @redfox-mx,

There is no issue and everything works really nice!

We just want to add strict types for this function and since lit is expecting these types I thought it would be nice to add them.

We are using your mount command implementation with some overwrites and since mount options are extracted in a type I was able to enhance the options types (as it is described here: https://docs.cypress.io/api/cypress-api/custom-commands#Overwrite-Existing-Commands). Probably here could be used similar approach?