html - Polymer 2.x 单元测试将可选内容传递给 fixture 以绑定(bind)到目标属性

标签 html unit-testing polymer-2.x

我正在尝试将数据插入测试夹具,但目前无法实现。返回此错误: “已获得要标记的模型,但模板不是可绑定(bind)类型”

我的测试代码如下:

<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>

这里问了类似的问题polymer 1.0 unit tests - how to bind properties to a child element?但答案不是我要找的,因为它是直接在子元素中定义目标属性

也在 Data binding in Polmyer's <test-fixture> 中这是完全相同的问题,但对我也不起作用。

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

最佳答案

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

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

关于html - Polymer 2.x 单元测试将可选内容传递给 fixture 以绑定(bind)到目标属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45241833/

相关文章:

javascript - framework7 在加载时不显示选项卡 1

unit-testing - 使用 Moq 模拟返回 IQueryable<MyObject> 的存储库

objective-c - 继承自 XCTestCase 子类

javascript - polymer 纸工具提示

javascript - Mustache.js 在空格之间分割 HTML 属性

javascript - HTML 单选按钮

c# - 如果一次运行一个单元测试,则单元测试通过良好,如果运行 "All Tests in Solution",则 FileLoadException

polymer - 有什么方法可以在 polymer 组件之间共享数据吗?

polymer - 未捕获的 DOMException : Failed to execute 'define' on 'CustomElementRegistry' (Polymer 2. 0)

php - 在原始 html 旁边编写 php 文件有哪些好的技巧?