1

我正在尝试使用 QUnit 设置 ember-testing 来测试我的 Ember.js 应用程序。

我的问题是应用程序没有在 QUnit 测试页面上呈现,因此 visit('/') 函数不起作用。

索引.html

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>MKTS Tests</title>
  <meta name="viewport" content="width=device-width" />

  <link rel="stylesheet" href="./bower_components/qunit/qunit/qunit.css">
  <!--
  <link rel="stylesheet" href="./css/foundation.css"> 
  <link rel="stylesheet" href="./css/app.css">
  -->
  <style type="text/css">
    #qunit-fixture, #app-root {
      position: relative;
      top: 0;
      left: 0;
      width: auto;
      height: auto;
    }
  </style>
</head>
<body>
  <div id="qunit"></div>
  <div id="qunit-fixture"></div>

  <!-- Libraries (Dependencies) -->
  <script src="../app/bower_components/requirejs/require.js"></script>
  <script src="../app/bower_components/jquery/dist/jquery.min.js"></script>
  <script src="../app/bower_components/handlebars/handlebars.js"></script>
  <script src="../app/bower_components/ember/ember.js"></script>
  <script src="../app/bower_components/ember-data/ember-data.js"></script>

  <!-- App and Templates -->
  <script src="../app/scripts/app.js"></script>
  <script src="../app/scripts/models/fleets.js"></script>
  <script src="../app/scripts/routes/application_route.js"></script>
  <script src="../app/scripts/routes/index_route.js"></script>
  <script src="../app/scripts/router.js"></script>
  <script src="../app/scripts/store.js"></script>

  <!-- Test Helpers -->
  <script src="./support/test_helper.js"></script>

  <!-- Test Library -->
  <script src="./bower_components/qunit/qunit/qunit.js"></script>

  <script src="./spec/integration.js"></script>
  <script src="./spec/unit.js"></script>

</body>
</html>

集成.js

test('hello world', function() {
  //debugger;
  //expect(1);
  MarketSetupAdminUi.reset();
  visit("/").then(function() {
    var title = find('title');
    equal(title.text(), 'Market Setup Tool', 'Title check');
  });
});

测试助手.js

(function (host) {
  var document = host.document;
  var App = host.MarketSetupAdminUi;

  var testing = function(){
    var helper = {
      container: function(){
        return App.__container__;
      },
      controller: function( name ){
        return helper.container().lookup('controller:' + name);
      },
      path: function(){
        return helper.controller('application').get('currentPath');
      }
    };
    return helper;
  };

  Ember.Test.registerHelper('path', function() {
    return testing().path();
  });

  Ember.Test.registerHelper('getFoodController', function() {
    return testing().controller('food');
  });

  // Move app to an element on the page so it can be seen while testing.
  document.write('<div id="test-app-container"><div id="ember-testing"></div></div>');
  App.rootElement = '#ember-testing';
  App.setupForTesting();
  App.injectTestHelpers();

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

}(window));
4

1 回答 1

0

我将应用程序更新为 Ember 1.10.0 和 Ember-data beta.15。

我计划使用 Ember-CLI 重新生成应用程序,它似乎有更好的测试。

于 2015-02-26T17:15:36.213 回答