Polymer / polymer

Our original Web Component library.
https://polymer-library.polymer-project.org/
BSD 3-Clause "New" or "Revised" License
22.05k stars 2.01k forks source link

Is there any other way to add unit test for Polymer 1.x component apart from Web component tester? #5727

Open swarnadipa-dev opened 3 months ago

swarnadipa-dev commented 3 months ago

Hi ,

I have a polymer 1.x component written in a .html file,

<dom-module id=“create-layout">
  <template>

    <input role="widget" name=“years” value="" autofocus required>
    </nuxeo-input>

    <input role="widget" name=“months” value="" autofocus required>
    </nuxeo-input>

    <input role="widget" name=“days” value="" autofocus required>
    </nuxeo-input>

  </template>

  <script>
    Polymer({
      is: 'create-layout',
      properties: {
        document: Object,
      },

      validate() {
        const years = this.shadowRoot.querySelector('input[name="years"]');
        const months = this.shadowRoot.querySelector('input[name="months"]');
        const days = this.shadowRoot.querySelector('input[name="days"]');
        if (parseInt(years.value, 10) === 0 && parseInt(months.value, 10) === 0 && parseInt(days.value, 10) === 0) {
          years.invalid = true;
          months.invalid = true;
          days.invalid = true;
          return false;
        }
        return true;
      }
    });
  </script>
</dom-module>

How do I write unit test for the validate() function ? As per the official Polymer documentation, web component tester is the way to write tests. Now, I have some other Polymer components as well in my project folder which are written in the Polymer 2.x syntax, and we have written unit tests for them using mocha and chai and web test runner. Will it be wise to combine web component tester with web-test-runner ? Is web component tester still being used today ?

I have tried importing the html file inside the test file, and also tried to access the dom-module by id, but none of these worked.