如何在 Ember 模型单元测试中检查属性属性类型?

Posted

技术标签:

【中文标题】如何在 Ember 模型单元测试中检查属性属性类型?【英文标题】:How to check properties attribute types in an Ember Model unit test? 【发布时间】:2017-07-27 11:06:16 【问题描述】:

我正在尝试编写一个用于测试 Ember 模型的实用程序。目前我有一个函数循环遍历模型中定义的属性(通过获取键)并将它们与预期的键匹配。

我想更进一步,检查属性在模型中的值是否正确。我希望能够检查 DS.attr(string/number/date etc) 和 Computed 属性。

我该怎么做?

【问题讨论】:

你必须更具体。也许可以举个例子。 【参考方案1】:

我已经解决了这个问题:

    model.eachAttribute((key, meta) => 
      const keyType = expected[key];
      assert.ok(expected[key], `the "$key" property is defined.`);
      assert.equal(meta.type, keyType, `the "$key" has the attribute type "$keyType".`); 
    );

【讨论】:

以上是关于如何在 Ember 模型单元测试中检查属性属性类型?的主要内容,如果未能解决你的问题,请参考以下文章