Ember.js:测试时组件属性未重置 [英] Ember.js: Component attribute not reset while testing
问题描述
我目前正在尝试对嵌套路由进行验收测试,该路由使用相同的组件两次,但使用不同的参数。这在我正常运行时工作正常,但是当我运行验收测试时,我注意到组件的参数没有被更新,这导致我的测试失败。以下是一些示例代码:
I am currently attempting an acceptance test on a nested route, which makes use of the same component twice, but with different arguments. This works fine when I run it normally, however as I run the acceptance test, I notice that the component's arguments aren't being updated, which causes my test to fail. Here is some sample code:
在 index.hbs
我有:
{{index-view model=model type='location'}}
我的 index-view
组件如下所示:
<h1>{{title}} List</h1>
{{listing-table model=model type=type}}
通过单击 listing-table
中的元素,然后转到 locations.show
路由,其中包含 link-to
locations.show.devices
路由。 locations.show.devices
路线包含:
By clicking on an element in the listing-table
, I then go to the locations.show
route, which contains a link-to
the locations.show.devices
route. The locations.show.devices
route contains:
{{listing-table model=model.devices type='device' exclude='locationName'}}
但是,在我的验收测试,我可以看到(通过在组件的javascript中回显这些属性),而模型
和类型
是正在更新, exclude
始终设置为最初调用组件时设置的内容。
However, in my acceptance tests, I can see (by echoing out these attributes in the component's javascript) that while model
and type
are being updated, exclude
is always set to whatever was set when the component was initially called.
现在,我检查了(通过 console.log()
)组件是否被重用,我可以看到 init()
和 didDestroyElement()
被调用两次,这意味着组件通过整个生命周期两次。但是,我真的不明白为什么我的 exclude
参数根本没有更新,为什么这只会在验收测试时发生?
Now, I have checked (via console.log()
) whether the component is being reused or not, and I could see that both init ()
and didDestroyElement ()
are called twice, which means that the component goes through an entire lifecycle twice. However, I can't really understand why my exclude
argument is not being updated at all, and why does this only happen while acceptance testing?
这是我正在做的一个精简版(当然它适用于Twiddle,但不适用于现实生活!)。
This is a stripped down version of what I'm doing (of course it works on Twiddle, but not in real life!).
推荐答案
{{listing-table model=model.devices type='device' exclude='locationName'}}
您传递了某个值locationName
(字符串)没有链接到该属性组件的 .locationName
。 (我是关于 locationName
的报价)
you pass certain value "locationName"
( string ) not link to the property .locationName
of component . ( I'm about quotes around locationName
)
你知道吗,是吗?
这篇关于Ember.js:测试时组件属性未重置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!