open-wc / open-wc

Open Web Components: guides, tools and libraries for developing web components.

Home Page:https://open-wc.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unable to test an updated attribute

rallets opened this issue · comments

Hi, I have a custom element defined as (I'm using Typescript, simplified version)

@customElement('md-paragraph')
export class Paragraph extends LitElement {

  @property({ type: String, attribute: true, reflect: true })
  value = '';

  render(): TemplateResult {
    return html`<div>${this.value}<slot></slot></div>`;
  }
}

and this test (I'm using Typescript, simplified version)

it('can update', async () => {
        const el = await fixture('<md-paragraph value="value 1"></md-paragraph>');

        expect(el.getAttribute('value')).to.equal('value 1'); // <= OK
        expect((el as any).value).to.eq('value 1'); // <= FAIL, expected undefined to equal 'value 1'

        (el as any).value = 'value 2';
        await elementUpdated(el);
        expect(el).dom.to.equal('<md-paragraph value="value 2"></md-paragraph>'); // FAIL; expected '<md-paragraph value="value 1">\n</md-paragraph>\n' to equal '<md-paragraph value="value 2">\n</md-paragraph>\n'
      });

Expected behavior

I will expect:

  • to have el.value = "value 1"
  • after the update, to have DOM as

Actual Behavior

  • el.value is undefined
  • the DOM doesn't update

Additional context

Latest available from open-wc template

[...]
"lit-element": "^2.5.1",
"lit-html": "^1.4.1",
[...]
"@open-wc/testing": "^2.5.33",
"@web/test-runner": "^0.13.16",

repo with the issue: open-wc-testing-issue

This is due to the same issues outlined in #2275 (comment)

close, as solution is the same as 2275