简体   繁体   English

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: 以下是一些示例代码:

In index.hbs I have: index.hbs我有:

{{index-view model=model type='location'}}

My index-view component looks like this: 我的index-view组件如下所示:

<h1>{{title}} List</h1>

{{listing-table model=model type=type}}

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. 通过单击listing-table的元素,然后转到locations.show路由,其中​​包含link-to locations.show.devices路由的link-to The locations.show.devices route contains: locations.show.devices路由包含:

{{listing-table model=model.devices type='device' exclude='locationName'}}

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. 但是,在我的验收测试中,我可以看到(通过在组件的javascript中回显这些属性),在更新modeltypeexclude总是设置为最初调用组件时设置的内容。

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. 现在,我检查了(通过console.log() )组件是否被重用,我可以看到init ()didDestroyElement ()都被调用了两次,这意味着组件经历了整个生命周期两次。 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? 但是,我真的不明白为什么我的exclude参数根本没有更新,为什么这只会在验收测试时发生?

This is a stripped down version of what I'm doing (of course it works on Twiddle, but not in real life!). 这是我正在做的精简版 (当然它适用于Twiddle,但不适用于现实生活!)。

{{listing-table model=model.devices type='device' exclude='locationName'}}

you pass certain value "locationName" ( string ) not link to the property .locationName of component . 你传递某些值"locationName" (字符串)没有链接到组件的属性.locationName ( I'm about quotes around locationName ) (我是关于locationName引用)

You know, yes? 你知道吗,是吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM