Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ssr-dom-shim in reactive-element is breaking test cases in vitest/happy-dom #3559

Closed
abbasc52 opened this issue Jan 11, 2023 · 2 comments · Fixed by #3561
Closed

ssr-dom-shim in reactive-element is breaking test cases in vitest/happy-dom #3559

abbasc52 opened this issue Jan 11, 2023 · 2 comments · Fixed by #3561
Assignees

Comments

@abbasc52
Copy link

Which package(s) are affected?

Lit Core (lit / lit-html / lit-element / reactive-element)

Description

as of v1.6.0 of reactive-element, it imports srr-dom-shim when environment is node.
When testing using dom emulation like happy-dom, it is loading the shim, which is causing test cases to fail.

Reproduction

https://stackblitz.com/edit/vitest-dev-vitest-7rrc4s?file=package.json,test%2Fbasic.test.ts

Workaround

force @lit/reactive-element dependency version to 1.5.0

Is this a regression?

Yes. This used to work, but now it doesn't.

Affected versions

Failing with @lit/reactive-element 1.6.0, working with 1.5.0

Browser/OS/Node environment

OS: Windows 11
Node Version: 14.19
npm version: 6.14.17

@aomarks
Copy link
Member

aomarks commented Jan 11, 2023

Thanks for filing!

Looks like this line from the Rollup config is not working as intended:

'extends HTMLElement': 'extends (globalThis.HTMLElement ?? HTMLElement)',

The published code simply has extends HTMLElement instead of extends (globalThis.HTMLElement ?? HTMLElement).

Will try to get a fix out today.

@augustjk
Copy link
Member

The fix for this is released with lit@2.6.1. Updating to the latest version in the stackblitgz repro above alleviates the original issue.

One of the assertion still fails

  it('should increment the count on each click', () => {
    getInsideButton()?.click()
    expect(getInsideButton()?.innerText).toContain('1')
  })

with the error

TypeError: childNode.textContent.replace is not a function

I think this is due to something with how happy-dom implements .innerText. Changing to

  it('should increment the count on each click', () => {
    getInsideButton()?.click()
    expect(getInsideButton()?.textContent).toContain('1')
  })

makes the test pass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
3 participants