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

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

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

我该怎么做?

【问题讨论】:

  • 你必须更具体。也许可以举个例子。

标签: ember.js ember-data


【解决方案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}".`); 
    });

【讨论】:

    猜你喜欢
    • 2012-06-26
    • 2015-04-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-07
    • 1970-01-01
    • 2019-06-21
    相关资源
    最近更新 更多