未捕获的类型错误:运行 QUnit 测试时无法调用未定义 Ember 数据的方法“extractId”

2024-04-15

我越来越

Uncaught TypeError: Cannot call method 'extractId' of undefined 

使用 QUnit 运行集成测试时。

失败的测试:

module "Points",
  setup: ->
    App.reset()
    Ember.run App, App.advanceReadiness

test "Index", ->
  visit("/points").then ->
    ok(exists(".title:contains('POINTS')"), "Retrieved title of points section")
    App.Point.find().then (points) ->
      equal(find(".listContainer li").length, points.get('length') , "Retrieved correct number of points")

单独运行此测试效果很好,但在模块内运行此测试会引发上述错误。 这好像是adapterForType(App.Point) https://github.com/emberjs/data/blob/master/packages/ember-data/lib/system/store.js#L1678返回未定义的值。

将测试更新为

test "Index", ->
  result = App.Point.find()
  visit("/points").then ->
    ok(exists(".title:contains('POINTS')"), "Retrieved title of points section")
    result.then (points) ->
      equal(find(".listContainer li").length, points.get('length') , "Retrieved correct number of points")

减轻误差。

返回值由adapterForType正确的测试是:

Ember.inspect(this.adapterForType(App.Point))
"{serializer: <DS.FixtureSerializer:ember455>, _attributesMap: [object Object], _configurationsMap: [object Object], _outstandingOperations: [object Object], _dependencies: [object Object]}"

有与此行为相关的建议吗?


当单独运行该测试时,适配器可能尚未创建/初始化。或者可能是第一次使用适配器时延迟初始化。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

未捕获的类型错误:运行 QUnit 测试时无法调用未定义 Ember 数据的方法“extractId” 的相关文章

随机推荐