简体   繁体   English

Ember.js:执行验收测试时消失的组件属性

[英]Ember.js: disappearing component properties while performing acceptance tests

I have a component listing-table which takes a number of properties, like this: 我有一个包含许多属性的组件listing-table ,如下所示:

{{listing-table model=model.devices type='user' exclude='customerName'}}

This works as intended, and the integration tests also work just fine. 这可以按预期工作,并且集成测试也可以正常工作。 However, my acceptance tests fail, because apparently my exclude property is not being taken into account while running an acceptance test. 但是,我的验收测试失败,因为显然在运行验收测试时未考虑我的exclude属性。

I have tested this by printing to console the value of this.get('exclude') in the component's javascript file and getting undefined . 我已经通过打印以在组件的javascript文件中控制台this.get('exclude')的值并获得undefined However, printing eg this.get('type') yields the expected results. 但是,例如打印this.get('type')产生预期的结果。

I have then, for testing purposes, removed exclude and replaced type 's value with it, ie type='endpointName,typeName' , however, I would get the previous value in the console, eg user . 然后,出于测试目的,我删除了exclude并将其替换为type的值,即type='endpointName,typeName' ,但是,我会在控制台中获取先前的值,例如user

This is all way beyond puzzling, and I'd really like to know what's the matter with acceptance test. 这完全是令人费解的,我真的很想知道验收测试有什么问题。 Any sort of hints are more than welcome, and thanks for your time! 任何提示都非常受欢迎,感谢您的宝贵时间!


EDIT: 编辑:

I have now edited my acceptance test to exclude clicking through various elements to get to the route that contains my listing-table component: 现在,我已经编辑了验收测试,以排除单击各种元素以到达包含listing-table组件的路线listing-table

From: 从:

visit('/users/1')
click('a:contains("Devices")')

To: 至:

visit('/users/1/devices')

And the test passes. 测试通过了。 I still don't understand why clicking through makes my component's properties disappear, whereas visiting the page directly works just fine. 我仍然不明白为什么单击可以使我的组件的属性消失,而直接访问页面就可以了。


EDIT 2: 编辑2:

So, here is some sample code. 因此,这是一些示例代码。 This is what my test looks like: 这是我的测试结果:

test('/customers/1/devices should display 5 devices', function (assert) {
  let type = server.create('endpoint-type')
  let user = server.create('user')
  let endpoint = server.create('endpoint', { type })
  server.createList('device', 5, { user })

  visit('/customers');
  click('a:contains("Customer 0")')
  click('a:contains("Devices")')
  andThen(function () {
    assert.equal(find('.device-listing').length, 5, 'should see 5 listings')
    assert.equal(find('th').text().trim(), 'IDModelManufacturerMACExtensionLocation', 'should only contain ID, Model, Manufacturer, MAC, Extension, and Location columns')
  })

Now, my Devices table should, in this case, omit the 'Customer' column, however, the column does appear in there, even though my component in devices.show.customers has been invoked with: 现在,在这种情况下,我的设备表应该省略“客户”列,但是,即使我的devices.show.customers组件已被调用,该列也确实出现在其中:

{{listing-table model=model.devices type='user' exclude='customerName'}}

My listing-table.js file basically uses this.get('exclude') inside the init () function to process the excludes, but as I said, if I add a console.log(this.get('exclude') in that file, I get undefined . 我的listing-table.js文件基本上在init ()函数中使用listing-table.js this.get('exclude')来处理排除项,但是正如我所说,如果我在console.log(this.get('exclude')添加console.log(this.get('exclude')该文件,我undefined


EDIT 3: 编辑3:

After more testing, I have made some progress, and the resulting question needs its own page, here . 经过更多测试之后,我已经取得了一些进步,所产生的问题需要在此处单独显示

Just a few thoughts: 只是一些想法:

  1. I assume this one has been done since you got green on your second attempt... are you using andThen to handle your assertions to make sure all of your async events are settled? 我认为这是自从您第二次尝试获得成功以来就已经完成了...您是否正在使用andThen处理您的断言以确保所有异步事件都得到解决?
  2. Is the model hook being triggered? 是否触发了模型挂钩? Depending on how you enter the route, the model hook will sometimes not get triggred: Why isn't my ember.js route model being called? 根据您输入路线的方式,有时有时不会触发模型挂钩: 为什么不调用ember.js路线模型?

Might be helpful to have some code to look at. 看看一些代码可能会有所帮助。

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

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