1
votes

I'm trying to setup ember-testing with QUnit to test my Ember.js application.

My problem is the app isn't rendering on the QUnit test page, and thus the visit('/') function isn't working.

index.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>

integration.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');
  });
});

test-helper.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));
1
Ember 1.6.1 Ember Data 1.0.0-beta.8.2a68c63amrlindsey

1 Answers

0
votes

I updated the app to Ember 1.10.0 and Ember-data beta.15.

I'm planning to regenerate the app using Ember-CLI, which appears to have better testing.