emberjs:使用 Pavlov/QUnit 进行测试会产生 TypeError:Object # 没有方法 'getHandler'
2024-03-18

警告:我是新手。预先感谢您的任何帮助。

Pavlov/QUnit 导致我的 ember 应用程序中的路由器出现问题。单独使用 QUnit 时,以下测试通过:

test "/contacts", ->
  expect(1)
  visit('/contacts').then ->
    ok(exists(".nav"), "The navbar was rendered")

但是当将巴甫洛夫与 QUnit 一起使用时,以下测试会失败:

describe 'contacts index', ->
    it 'does render index', ->
      visit('/contacts').then ->
        assert(exists(".nav")).isTrue('The navbar was rendered')

并在执行以下命令时在collectObjects方法中产生“没有方法'getHandler'”错误:

var handler = router.getHandler(result.handler);

堆栈跟踪如下:

TypeError: Object #<Object> has no method 'getHandler'
    at collectObjects (http://localhost:3000/assets/test_helper.js:37674:28)
    at Object.Router.handleURL (http://localhost:3000/assets/test_helper.js:37347:9)
    at Ember.Router.Ember.Object.extend.handleURL (http://localhost:3000/assets/test_helper.js:38135:17)
    at Ember.Application.Ember.Namespace.extend.handleURL (http://localhost:3000/assets/test_helper.js:41451:12)
    at http://localhost:3000/assets/test_helper.js:18367:19
    at Object.Ember.handleErrors (http://localhost:3000/assets/test_helper.js:14228:17)
    at invoke (http://localhost:3000/assets/test_helper.js:18365:16)
    at Object.tryable (http://localhost:3000/assets/test_helper.js:18550:14)
    at Object.Ember.tryFinally (http://localhost:3000/assets/test_helper.js:15023:24)
    at Object.Ember.run (http://localhost:3000/assets/test_helper.js:18554:16)

像这样设置 Ember-testing/QUnit 测试:

App.setupForTesting();
App.injectTestHelpers();

module("Integration Tests", {
  setup: function() {
    App.reset();
    Ember.run(App, App.advanceReadiness);
  }
});

当然,更换App与您的应用程序的名称。

The new 测试指南 http://emberjs.com/guides/testing/integration/目前建议这样做,但不显示代码。

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

emberjs:使用 Pavlov/QUnit 进行测试会产生 TypeError:Object # 没有方法 'getHandler' 的相关文章

随机推荐