我目前正在尝试对嵌套路由进行验收测试,它两次使用相同的组件,但参数不同。当我正常运行它时它工作正常,但是当我运行验收测试时,我注意到组件的参数没有更新,这导致我的测试失败。这是一些示例代码:
在 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
路由包含:
{{listing-table model=model.devices type='device' exclude='locationName'}}
但是,在我的验收测试中,我可以看到(通过在组件的 javascript 中回显这些属性)当 model
和 type
正在更新时, exclude
始终设置为最初调用组件时设置的值。
现在,我已经检查(通过 console.log()
)组件是否被重用,我可以看到 init ()
和 didDestroyElement ()
被调用了两次,这意味着组件经历了整个生命周期两次。但是,我真的不明白为什么我的 exclude
参数根本没有更新,为什么这只在验收测试时发生?
This is a stripped down version of what I'm doing (当然它适用于 Twiddle,但不适用于现实生活!)。
最佳答案
{{listing-table model=model.devices type='device' exclude='locationName'}}
您传递的特定值 "locationName"
(字符串)未链接到组件的属性 .locationName
。 (我是关于 locationName
的引号)
你知道吗?
关于javascript - Ember.js:测试时未重置组件属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45682185/