From e312658b3f82f2497b9e2226e64dc1d53c4efd55 Mon Sep 17 00:00:00 2001 From: Jason Williams Date: Mon, 1 Jun 2015 11:41:05 -0500 Subject: [PATCH] [BUGFIX release] Ensure handleURL called after setURL in visit helper Refs #11201 (cherry picked from commit f869e4ba68c54444b2a800a724b4869a94884a5f) --- packages/ember-testing/lib/helpers.js | 8 ++++++- .../ember-testing/tests/acceptance_test.js | 24 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/packages/ember-testing/lib/helpers.js b/packages/ember-testing/lib/helpers.js index b562018a01d..de9d7608ebf 100644 --- a/packages/ember-testing/lib/helpers.js +++ b/packages/ember-testing/lib/helpers.js @@ -57,8 +57,14 @@ 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) { @@ -66,7 +72,7 @@ function visit(app, url) { run(app, 'advanceReadiness'); delete router['initialURL']; } else { - run(app.__deprecatedInstance__, 'handleURL', url); + shouldHandleURL = true; } return app.testHelpers.wait(); diff --git a/packages/ember-testing/tests/acceptance_test.js b/packages/ember-testing/tests/acceptance_test.js index bc74127e9cb..214a45523c8 100644 --- a/packages/ember-testing/tests/acceptance_test.js +++ b/packages/ember-testing/tests/acceptance_test.js @@ -30,6 +30,8 @@ QUnit.module("ember-testing Acceptance", { this.route('comments'); this.route('abort_transition'); + + this.route('redirect'); }); App.IndexRoute = EmberRoute.extend({ @@ -67,6 +69,12 @@ QUnit.module("ember-testing Acceptance", { } }); + App.RedirectRoute = EmberRoute.extend({ + beforeModel() { + this.transitionTo('comments'); + } + }); + App.setupForTesting(); }); @@ -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'); + }); +});