Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Polymer 2.x unit test pass optional content to fixture in order to bind to a target property

I am trying to insert data into the test fixture but couldn't achieve so far. Returns this error: "was given a model to stamp, but the template is not of a bindable type"

My test code is like below:

<test-fixture id="myFixture">
  <template is="dom-template">
    <my-element given-input="[[selectedInput]]"></myElement>
  </template>
</test-fixture>

<script>
  suite('<my-element>', function() {

    var myEl;

    setup(function() {
      myEl = fixture('myFixture', {selectedInput: 'test input'});
    });

    test('initiates my-element', function() {

      // fails as givenInput returns "[[selectedInput]]"
      assert.equal(myEl.givenInput, 'test input');
    });
  });
</script>

Similar question was asked here polymer 1.0 unit tests - how to bind properties to a child element? but the answer is not what I look for since it is directly defining target property in the child element

Also in Data binding in Polmyer's <test-fixture> it is very same issue but didn't work for me either.

My question is about, how can we pass a property down to the element through test fixture in Polymer 2.x unit testing?

like image 974
user2683387 Avatar asked Oct 18 '22 08:10

user2683387


1 Answers

After some more research, I found out that this was an already known issued which can be tracked here https://github.com/PolymerElements/test-fixture/issues/47.

The only possible workaround I have found to continue with the unit testing is to pass givenInput into myEl and removing given-input="[[selectedInput]]" from my-elemet inside test-fixture. Which is not the proper approach but at least makes testing possible.

like image 76
user2683387 Avatar answered Oct 20 '22 22:10

user2683387