sand4rt / playwright-ct-web

Playwright Web component testing.
https://www.npmjs.com/package/@sand4rt/experimental-ct-web
MIT License
41 stars 3 forks source link

Allow pure web component mounting #7

Closed rstoneIDBS closed 1 year ago

rstoneIDBS commented 1 year ago

For most web component test cases (in my experience anyway) - you simply want to mount the web component the same way you would mount it in an app, i.e. as a string: <my-web-component some-attribute="foo">bar</my-web-component> This (very hacky) fix allows the above option whilst keeping the existing behaviour if necessary.

sand4rt commented 1 year ago

For most web component test cases (in my experience anyway) - you simply want to mount the web component the same way you would mount it in an app, i.e. as a string: <my-web-component some-attribute="foo">bar</my-web-component> This (very hacky) fix allows the above option whilst keeping the existing behaviour if necessary.

Thank you for another PR! It is nice that the component used in testing is used in the same way as in production. However the cons i see are:

  1. It will destroy type safety
  2. It is not consistent with Playwright's API
  3. Would have to register the component manually as we cannot resolve the component based on a string

If we do this, i think this should be added to Playwright first. Someone else asked the same thing for Svelte BTW.: https://github.com/microsoft/playwright/issues/18758#issuecomment-1319599376

Maybe we should create a separate issue for now to collect upvotes?

rstoneIDBS commented 1 year ago

For most web component test cases (in my experience anyway) - you simply want to mount the web component the same way you would mount it in an app, i.e. as a string: <my-web-component some-attribute="foo">bar</my-web-component> This (very hacky) fix allows the above option whilst keeping the existing behaviour if necessary.

Thank you for another PR! It is nice that the component used in testing is used in the same way as in production. However the cons i see are:

  1. It will destroy type safety
  2. It is not consistent with Playwright's API
  3. Would have to register the component manually as we cannot resolve the component based on a string

If we do this, i think this should be added to Playwright first. Someone else asked the same thing for Svelte BTW.: microsoft/playwright#18758 (comment)

Maybe we should create a separate issue for now to collect upvotes?

I've discovered a problem with this 'hack' anyway :) It's not un-mounting the component(s) between tests and I also have to have at least one test that creates the component via the standard mechanism otherwise it doesn't recognise any tests. So yes, probably safe to ignore this for now - however it is (IMO) a much nicer way to component test web components than creating them using JS.