【问题标题】:Ember.js: Stuck with initial integration testEmber.js:卡在初始集成测试中
【发布时间】:2013-09-11 14:21:45
【问题描述】:

在 1.0 版本发布后,我正在探索 Ember,并认为它进展顺利,直到我尝试关注 this tutorial on integration testing。它写得很好而且很有指导意义,但是我已经在调试设置测试几天了:/ Noob pains...

This gist 显示 qunit 上的测试和错误。我正在按照 tute 的设置进行操作,我在其他地方也看到过。

在 IRC 上有人指出这个 tute 使用 R5,而不是最新的 1.0 版本。他不知道从那时起余烬测试是否发生了变化,但这可能是罪魁祸首。

关于我可能做错的任何想法?我知道这一定很愚蠢:)

(在 Rails 4 中使用 Ember)

更新

Márcio 的小提琴让我玩弄添加和删除东西,直到我复制了错误。结果我没有设置任何模板,测试也不喜欢这样,尽管应用程序加载时没有错误,并且 ember 检查器看到了路由等。

【问题讨论】:

  • 嗨,我在这里做了一个简单的 jsfiddle 并工作了 jsfiddle.net/marciojunior/GveWH。你能显示转换到“/”时执行的代码吗?以IndexRoute为例,索引模板...
  • 马西奥,谢谢!我最终使用您的小提琴进行了调试,并发现了问题所在 - 缺少车把脚本标签:P
  • 您想创建一个答案,以便我检查它是否正确?只有公平,因为这解决了我的问题......也很快

标签: javascript ember.js coffeescript qunit ember-testing


【解决方案1】:

我按照教程完成了这项工作:

Javascript:

App = Ember.Application.create();

App.Store = DS.Store.extend({
    adapter: DS.FixtureAdapter
});

App.Router.map(function() {
    this.route('edit', { path: ':person_id' });
});

App.IndexRoute = Ember.Route.extend({
  model: function() {
      return this.store.find('person');
  }
});

App.Person = DS.Model.extend({
    firstName: DS.attr('string'),
    lastName: DS.attr('string')
});

App.Person.FIXTURES = [
    {id: 1, firstName: 'Kris', lastName: 'Selden'},
    {id: 2, firstName: 'Luke', lastName: 'Melia'},
    {id: 3, firstName: 'Formerly Alex', lastName: 'Matchneer'}
];

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

function exists(selector) {
  return !!find(selector).length;
}

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

test("Check HTML is returned", function() {

  visit("/").then(function() {
    ok(exists("*"), "Found HTML!");
  });

});

模板:

<div id="qunit"></div>
<div id="qunit-fixture"></div>
<div id="ember-testing-container"><div id="ember-testing"></div></div>

<script type="text/x-handlebars" data-template-name="application">
    <h1>ember-latest jsfiddle</h1>
    {{outlet}}
</script>

<script type="text/x-handlebars" data-template-name="index">
  <h2>Index Content:</h2>
  <ul>
  {{#each}}
      <li>{{#link-to 'edit' this}}  {{firstName}} {{lastName}} {{/link-to}}</li>
  {{/each}}
   </ul>
</script>

<script type="text/x-handlebars" data-template-name="edit">
  <h2>Edit:</h2>
  <p id='name'>
      {{firstName}}
  </p>
</script>

这是摆弄这个工作http://jsfiddle.net/marciojunior/GveWH/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-02-15
    • 1970-01-01
    • 1970-01-01
    • 2018-02-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多