Uncaught TypeError: Cannot call method 'extractId' of undefined Ember Data while running QUnit tests

五迷三道 提交于 2019-12-07 18:26:19

问题


I'm getting

Uncaught TypeError: Cannot call method 'extractId' of undefined 

while running integration tests with QUnit.

The failing test:

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")

Running this test in isolation works well but running this test within the module it throws the error mention above. It seems like adapterForType(App.Point) returns an undefined value.

Updating the test to

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")

mitigates the error.

The value retuned by adapterForType in the correct test is:

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

Any suggestion related to this behavior?


回答1:


It's possible that when running that test in isolation the adapter hasn't yet been created/initialized. Or maybe it's lazy initialized the first time the adapter has been used.



来源:https://stackoverflow.com/questions/18312596/uncaught-typeerror-cannot-call-method-extractid-of-undefined-ember-data-while

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!