mardi 24 décembre 2019

open-wc/karma ChromeHeadless testing - Failed to construct 'HTMLElement': this instance is already constructed

I have a project using lit-elements and web-components for which I've written some tests using Karma. I'm using the open-wc stack, my tests were running fine. I just updated my components and now my tests are crashing. The tests are using ChromeHeadless with no sandbox mode.

I already went on a few SW posts and saw that the error could potentially be solved using polyfills but I'm not running webpack for the tests, and I got it to work before without the needing polyfills...

I'm running karma start --coverage and run into this error.

HeadlessChrome 79.0.3945 (Windows 10.0.0)
Error: Uncaught InvalidStateError: Failed to construct 'HTMLElement': this instance is already constructed (node_modules/lit-element/lib/updating-element.js:96)
    at TemplateInstance._clone (node_modules/lit-html/src/lib/template-instance.ts:99:18)
    at NodePart.__commitTemplateResult (node_modules/lit-html/src/lib/parts.ts:276:33)
    at NodePart.commit (node_modules/lit-html/src/lib/parts.ts:218:12)
    at render (node_modules/lit-html/src/lib/render.ts:55:12)
    at render (node_modules/@open-wc/testing-helpers/src/litFixture.js:37:3)
    at litFixtureSync (node_modules/@open-wc/testing-helpers/src/litFixture.js:54:14)
    at litFixture (node_modules/@open-wc/testing-helpers/src/fixture-no-side-effect.js:52:12)
    at Context.fixture (components/form-element/test/form-data.test.js:233:22)

form-data.test.js

import { fixture, elementUpdated } from '@open-wc/testing';

[...]

describe('<form-data>', () => {
  it('render form', async () => {
    // This line seems to be problematic
    const el = await fixture(template);
    await elementUpdated(el);
    expect(el).shadowDom.to.equal(`
      <form novalidate>
        <slot>
        </slot>
      </form>
    `);
  });

Aucun commentaire:

Enregistrer un commentaire