Polymer 2.x unit test将可选内容传递给fixture,以便绑定到target属性

use*_*387 5 html unit-testing polymer-2.x

我试图将数据插入测试夹具但到目前为止无法实现.返回此错误: "was given a model to stamp, but the template is not of a bindable type"

我的测试代码如下:

<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>
Run Code Online (Sandbox Code Playgroud)

类似的问题在这里被问到聚合物1.0单元测试 - 如何将属性绑定到子元素?但答案不是我想要的,因为它直接定义了子元素中的目标属性

同样在Polmyer的<test-fixture>中的数据绑定中,这是非常相同的问题,但对我来说也不起作用.

我的问题是,如何通过Polymer 2.x单元测试中的测试夹具将属性传递给元素?

use*_*387 3

经过更多研究,我发现这是一个已知的问题,可以在此处跟踪https://github.com/PolymerElements/test-fixture/issues/47

我发现继续进行单元测试的唯一可能的解决方法是传递givenInput到内部并从内部myEl删除。这不是正确的方法,但至少使测试成为可能。given-input="[[selectedInput]]"my-elemettest-fixture