In test cases how to stop code execution while route transition is in progress?

In my app there is a link which changes the route upon clicking, now I am trying to test this behavior through QUnit, but my route change assertion is getting executed before route changes. So I need a way to stop code execution till the time route transition happens.

test("Test App", function () {
        visit("/").then(function () {            

            click("some selector");

            equal(controllerFor('application').currentPath, "newroute", "Successfully change route...");
        })
    });
1 Like

There are a few techniques for doing this, but it depends on what’s causing the delay. This usually happens when you have async behaviour that’s executed during route transition. Is this the case?

Thanks for the response, I don’t have any async behavior in my app, its simple html view

Hmm… it might be as simple as the fact that your test cost isn’t actually waiting for click to happen before running the test. The click helper returns a promise that you can use to make sure that your tests run after the click is finished.

Internally, Ember will automatically find the last promise from visit and chain click to it, so you don’t have to chain them. equal doesn’t now about promises, so you have to explicitly tell the test to run it after the click promise is fulfilled.

test("Test App", function () {
  visit("/");
  click("some selector")
    .then(function(){
      equal(controllerFor('application').currentPath, "newroute", "Successfully change route...");
    });
});