gpt4 book ai didi

javascript - Ember 测试访问 promise 不起作用

转载 作者:行者123 更新时间:2023-11-29 10:45:38 25 4
gpt4 key购买 nike

我正在尝试使用 QUnit 设置 ember-testing 以测试我的 Ember.js 应用程序,遵循这些博客文章: Getting started with integration testing ember.js using ember-testing and qunit-rails

我的问题是,每次我尝试使用 ember-testings 访问助手访问路由时,visit(<route>).then不会调用 promise,但会呈现正确的 View 。

这是我当前的 Ember.js 设置:(我也尝试过测试版)

  • Ember:1.3.0-beta.1+canary.8f5b6e20
  • Ember 数据:1.0.0-beta.4+canary.e7996c4d
  • Handlebars :1.1.1
  • jQuery : 1.10.2

编辑 1:

QUnit 仅显示测试正在运行,没有失败或成功消息。

测试:

module("Ember.js Library", {
setup: function() {
Ember.run(App, App.advanceReadiness);
},
teardown: function() {
App.reset();
}
});

test("Check HTML is returned", function() {
expect(2);
visit("/").then(function() {
ok(false, "Show me an error!");
});
});

测试设置 (test_helper.js):

document.write('<div id="ember-testing-container"><div id="ember-testing"></div></div>');
document.write('<style>#ember-testing-container { position: absolute; background: white; bottom: 0; right: 0; width: 640px; height: 384px; overflow: auto; z-index: 9999; border: 1px solid #ccc; } #ember-testing { zoom: 50%; }</style>');

App.rootElement = '#ember-testing';
App.setupForTesting();
App.injectTestHelpers();

编辑 2:

QUnit 似乎工作正常。如果我使用以下测试,则 QUnit 测试运行程序会显示正确的失败。但是,如果我像上面那样在 promise 中包含断言,那么 QUnit 会显示测试正在运行,但测试似乎并没有停止。

test("Check HTML is returned", function() {
expect(2);
ok(false, "Show me an error!");
});

最佳答案

问题出在Ember-Simple-Auth插件,有一个bug在我使用的版本中。我升级了,现在一切正常。

@kingpin:感谢您提供的最小工作示例,在将它与我的代码进行比较后我意识到,挂断的原因一定是其他原因,所以我找到了上面提到的插件。

关于javascript - Ember 测试访问 promise 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20196325/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com