Skip to content

Commit

Permalink
[BUGFIX release] Ensure handleURL called after setURL in visit helper
Browse files Browse the repository at this point in the history
  • Loading branch information
jaswilli committed Jun 1, 2015
1 parent f932861 commit f869e4b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/ember-testing/lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,22 @@ function focus(el) {

function visit(app, url) {
var router = app.__container__.lookup('router:main');
var shouldHandleURL = false;

app.boot().then(function() {
router.location.setURL(url);

if (shouldHandleURL) {
run(app.__deprecatedInstance__, 'handleURL', url);
}
});

if (app._readinessDeferrals > 0) {
router['initialURL'] = url;
run(app, 'advanceReadiness');
delete router['initialURL'];
} else {
run(app.__deprecatedInstance__, 'handleURL', url);
shouldHandleURL = true;
}

return app.testHelpers.wait();
Expand Down
24 changes: 24 additions & 0 deletions packages/ember-testing/tests/acceptance_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ QUnit.module("ember-testing Acceptance", {
this.route('comments');

this.route('abort_transition');

this.route('redirect');
});

App.IndexRoute = EmberRoute.extend({
Expand Down Expand Up @@ -67,6 +69,12 @@ QUnit.module("ember-testing Acceptance", {
}
});

App.RedirectRoute = EmberRoute.extend({
beforeModel() {
this.transitionTo('comments');
}
});

App.setupForTesting();
});

Expand Down Expand Up @@ -355,3 +363,19 @@ QUnit.test("test must not finish while asyncHelpers are pending", function () {
});
}
});

QUnit.test('visiting a URL and then visiting a second URL with a transition should yield the correct URL', function () {
expect(2);

visit('/posts');

andThen(function () {
equal(currentURL(), '/posts', 'First visited URL is correct');
});

visit('/redirect');

andThen(function () {
equal(currentURL(), '/comments', 'Redirected to Comments URL');
});
});

0 comments on commit f869e4b

Please sign in to comment.