Skip to content

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

Open
@swarnadipa-dev

Description

@swarnadipa-dev

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions