【问题标题】:Why following test doesn't pass?为什么以下测试不通过?
【发布时间】:2014-10-18 00:17:13
【问题描述】:

我有以下 EmberJS/Konacha 代码。有谁知道为什么测试没有通过?

编辑:

我添加了测试属性值而不是引用的测试用例。

#= require ../spec_helper

describe "Zaptax.v2014.App.AnswersLookup", ->
  beforeEach( ->
    Test.store = TestUtil.lookupStore()
  )

  it 'finds the answer by reference', ->
    page = Test.store.push Zaptax.v2014.App.PageModel, {id: 666, sequence: 123}

    assert.equal Test.store.find('page', 666).get('sequence'), 123

返回:

Failed: Zaptax.v2014.App.AnswersLookup finds the answer by reference
  AssertionError: expected undefined to equal 123

【问题讨论】:

  • 这很难说,但看起来好像您正在尝试测试两个对象的相等性 - 这将始终返回 false。
  • 你认为我可以在哪里寻找任何线索?
  • Test.store.find... 至少应该返回 PageModel 实例,但它返回空白 Object ()
  • @LeszekA 不要忘记find 是异步的并且返回一个promise对象。
  • 我使用 localstorage 作为适配器

标签: javascript ember.js ember-data konacha


【解决方案1】:

看起来好像您正在尝试测试两个对象的相等性 - 这将始终返回 false。例如:

var a = {};
var b = {};
assert(a === b); // false

您可能需要做的是检查对象属性的值是否与一系列断言相等。

var a = { name: 'Bob' };
var b = { name: 'Bob' };
assert(a.name === b.name); // true

【讨论】:

  • 按照您的提示,我还有另一个测试用例,但问题是商店不包含模型实例。
猜你喜欢
  • 1970-01-01
  • 2018-01-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-10-12
  • 1970-01-01
相关资源
最近更新 更多