Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Web Component Tester: Accessing the DOM

I have hundreds of Polymer test suites. At the end of each test, I'd like to access the DOM to do some custom quality checks.

Would writing a wct plugin work? If so, how should I access the DOM from within a plugin?

Thanks in advance!

like image 731
x74x61 Avatar asked Jan 28 '26 13:01

x74x61


1 Answers

No plugin necessary. You could already access the DOM of the test fixture with the native DOM APIs (e.g., el.querySelector()) or with Polymer instance methods (e.g., el.$$() or el.getEffectiveChildren()). I verified this with Shady and Shadow DOMs on Chrome 53 and 56.

This example adds a couple DOM-related assertions to afterEach(), which runs after every test:

<test-fixture id="basic">
  <template>
    <my-app></my-app>
  </template>
</test-fixture>

<script>
  describe('my-app', function() {
    var el;

    beforeEach(function() {
      el = fixture('basic');
    });

    afterEach(function() {
      expect(el.$$('h2').textContent).to.have.string('Hello');
      expect(el.querySelectorAll('*')).to.have.lengthOf(2);
    });

    it('instantiating the el works', function() {
      expect(el.is).to.equal('my-app');
    });
  });
</script>
like image 167
tony19 Avatar answered Jan 30 '26 06:01

tony19