Skip to content

Can't get data bound fixtures to work with v3.0.0-rc.1 #47

@pghalliday

Description

@pghalliday

Description

I tried to do the same as I did in Polymer 1.x with test-fixture v1.1.2, using the is="dom-template" attribute on my template and also tried using dom-bind as documented here https://www.polymer-project.org/2.0/docs/devguide/templates#dom-bind

But I cannot get data bound fixtures to work with a fresh polymer-2-application using test-fixture v3.0.0-rc.1

I suspect I'm doing something wrong :s

Expected outcome

Bound attributes are rendered with bound data

Actual outcome

Bound attributes are not rendered with bound data

Steps to reproduce

To a fresh polymer-2-application generated with polymer-cli v0.18.0-pre.13 (installs text-fixture v3.0.0-rc.1) add the following simple component as src/text.html

<link rel="import" href="../../../bower_components/polymer/polymer.html">

<dom-module id="my-text">
  <template>
    <div id="text">[[text]]</div>
  </template>
  <script>
    class MyText extends Polymer.Element {
      static get is() {
        return 'my-text';
      }

      static get properties() {
        return {
          text: String,
        };
      }
    }
    customElements.define(MyText.is, MyText);
  </script>
</dom-module>

And the following test as test/text.html

<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, minimum-scale=1, initial-scale=1, user-scalable=yes">

    <title>my-list test</title>

    <script src="../../webcomponentsjs/webcomponents-lite.js"></script>
    <script src="../../web-component-tester/browser.js"></script>

    <link rel="import" href="../src/text.html">
  </head>
  <body>
    <test-fixture id="myText">
      <template is="dom-template">
        <my-text text="[[text]]"></my-text>
      </template>
    </test-fixture>
    <script>
      describe('my-text', function() {
        var myText;

        beforeEach(function(done) {
          myText = fixture('myText', {
            text: 'hello'
          });
          flush(done);
        });

        it('should display the text', function() {
          expect(myText.root.querySelector('#text').textContent).to.eql('hello');
        });
      });
    </script>
  </body>
</html>

Then run polymer test or wct, etc

The test fails with:

expected '[[text]]' to deeply equal 'hello'
  Context.<anonymous> at text.html:32

NB. The equivalent test with an equivalent polymer 1.x component succeeds

I also got this error in the console

test-fixture.html:296 test-fixture#myText "was given a model to stamp, but the template is not of a bindable type"
stamp @ test-fixture.html:296
createFrom @ test-fixture.html:200
(anonymous) @ test-fixture.html:176
forElements @ test-fixture.html:277
create @ test-fixture.html:174
fixture @ stub.js:3
(anonymous) @ VM528 text.html:25
callFnAsync @ mocha.js:4470
Runnable.run @ mocha.js:4420
next @ mocha.js:4801
(anonymous) @ mocha.js:4831
timeslice @ mocha.js:82

Browsers Affected

  • Chrome
  • Firefox
  • Safari 9
  • Safari 8
  • Safari 7
  • Edge
  • IE 11
  • IE 10

Aside

I also tried with the dom-bind element like this

    <test-fixture id="myText">
      <dom-bind>
        <template>
          <my-text text="[[text]]"></my-text>
        </template>
      </dom-bind>
    </test-fixture>

But that fails in both Polymer 1.x and the Polymer 2 RC with the following error

Failed to execute 'removeChild' on 'Node': The node to be removed is not a child of this node.
     HTMLElement.<anonymous> at /components/test-fixture/test-fixture.html:271
     HTMLElement.forElements at /components/test-fixture/test-fixture.html:277
  HTMLElement.removeElements at /components/test-fixture/test-fixture.html:270
          HTMLElement.create at /components/test-fixture/test-fixture.html:172
         Context.<anonymous> at text.html:27

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions