samedi 18 avril 2020

Test lit-element with open-wc, karma, chai

I have been struggling to find a way to unit test a simple lit-element webcomponent i have been working on.

I ended up going with the open-wc testing. I installed it via npm init @open-wc, chose testing, karma and installed all needed dependencies.

I can run simple test functions, so i think the testing platform is working. What i can't get working is testing the custom element.

At the moment i have something like this:

import { html, fixture, expect } from '@open-wc/testing';
import MyButton from '../src/my-button';

describe('Test MyButton', () => {
  it('Has "default" as default type value', async () => {
    const el = (await fixture(html`<burgton-button></burgton-button>`));
    expect(el.type).to.equal('default');
  });
});

and when i run the test it fails with the message:

 AssertionError: expected undefined to equal 'default'

   + expected - actual

   -[undefined]
   +"default"

PS: If you know of any other good ways to test lit-element components, i would also appreciate it!

Thank you!

Aucun commentaire:

Enregistrer un commentaire