Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up boot process #10271

Merged
merged 15 commits into from
Jan 30, 2015
Prev Previous commit
Next Next commit
Adds simple visit() test
  • Loading branch information
Tom Dale and Yehuda Katz authored and tilde-engineering committed Jan 30, 2015
commit 9fb11dd9aec385957b67986f56c8955d6e5e7566
1 change: 1 addition & 0 deletions packages/ember-application/lib/system/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,7 @@ if (Ember.FEATURES.isEnabled('ember-application-visit')) {
*/
visit: function(url) {
var instance = this.buildInstance();
this.runInstanceInitializers(instance);

var renderPromise = new Ember.RSVP.Promise(function(res, rej) {
instance.didCreateRootView = function(view) {
Expand Down
46 changes: 43 additions & 3 deletions packages/ember-application/tests/system/visit_test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
import run from "ember-metal/run_loop";
import Application from "ember-application/system/application";
import ApplicationInstance from "ember-application/system/application-instance";
import Router from "ember-routing/system/router";
import compile from "ember-template-compiler/system/compile";

function createApplication() {
var app = Application.extend().create({
autoboot: false
var App = Application.extend().create({
autoboot: false,
LOG_TRANSITIONS: true,
LOG_TRANSITIONS_INTERNAL: true,
LOG_ACTIVE_GENERATION: true
});

return app;
App.Router = Router.extend();

return App;
}

if (Ember.FEATURES.isEnabled('ember-application-visit')) {
Expand Down Expand Up @@ -42,4 +50,36 @@ if (Ember.FEATURES.isEnabled('ember-application-visit')) {
});
});
});

QUnit.test("visit() returns a promise that resolves when the view has rendered", function(assert) {
QUnit.expect(3);
QUnit.stop();

var app;

run(function() {
app = createApplication();
app.instanceInitializer({
name: 'register-application-template',
initialize: function(app) {
app.registry.register('template:application', compile('<h1>Hello world</h1>'));
}
});
});

assert.equal(Ember.$('#qunit-fixture').children().length, 0, "there are no elements in the fixture element");

app.visit('/').then(function(instance) {
QUnit.start();
assert.ok(instance instanceof ApplicationInstance, "promise is resolved with an ApplicationInstance");

run(instance.view, 'appendTo', '#qunit-fixture');
assert.equal(Ember.$("#qunit-fixture > .ember-view h1").text(), "Hello world", "the application was rendered once the promise resolves");

instance.destroy();
}, function(error) {
QUnit.start();
assert.ok(false, "The visit() promise was rejected: " + error);
});
});
}