Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
swarnadipa-dev opened this issue Mar 11, 2024 · 0 comments

Comments

@swarnadipa-dev
Copy link

swarnadipa-dev commented Mar 11, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant