【问题标题】:Mocking conditional computed property in Ember component test在 Ember 组件测试中模拟条件计算属性
【发布时间】:2018-02-13 19:24:57
【问题描述】:

我试图在渲染组件之前简单地模拟计算的属性返回值。尝试this.set('isHome', true) 不起作用,因为我无法将它传递给组件。

组件[逻辑]:

isHome: false

组件[模板]:

{{#if isInbox}}
  <p id="maintext">Text</p>
{{/if}}

测试:

test('Block is visible on the homepage', function(assert) {
  assert.expect(1);
  this.set('isHome', true); // Does nothing
  this.render(template);
  let maintext = this.$("#maintext")
  this.asyncWait(assert, () => {
    assert.ok(maintext);
  });
});

这是一个非常粗略的布局轮廓,带有一个计算属性,然后用于在页面上显示或不显示块。如何将该计算属性覆盖为 true 以强制显示该块?

【问题讨论】:

    标签: javascript unit-testing ember.js


    【解决方案1】:

    与一位同事进一步研究,他们确认应避免尝试直接在测试中编辑计算属性。

    相反,他们建议更改用于设置该 ComputedProperty 的值。就我而言,我正在检查当前路径是否包含单词。

    因此,与其尝试将计算属性设置为true,不如我可以模拟路径并包含我正在寻找的单词,以便它评估为true

    希望这对以后的人有所帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-12-24
      • 2014-08-30
      • 1970-01-01
      • 1970-01-01
      • 2015-01-16
      • 1970-01-01
      • 2016-01-19
      相关资源
      最近更新 更多