未捕获TypeError:运行QUnit测试时,无法调用未定义的Ember数据的方法“extractId” [英] Uncaught TypeError: Cannot call method 'extractId' of undefined Ember Data while running QUnit tests

查看:119
本文介绍了未捕获TypeError:运行QUnit测试时,无法调用未定义的Ember数据的方法“extractId”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在获得

Uncaught TypeError: Cannot call method 'extractId' of undefined 

同时使用QUnit进行集成测试。

while running integration tests with 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) 返回未定义的值。

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.

将测试更新为

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]}"

与此行为有关的任何建议?

Any suggestion related to this behavior?

推荐答案

可能的是,当隔离运行该测试时,该适配器尚未被创建/初始化。或者也许它是第一次使用适配器时被初始化。

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.

这篇关于未捕获TypeError:运行QUnit测试时,无法调用未定义的Ember数据的方法“extractId”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆