我正在尝试将数据插入测试夹具,但目前无法实现。返回此错误:
“已获得要标记的模型,但模板不是可绑定(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/