ember octane test-helpers: currentURL() returns addressbar URL()

345 Views Asked by At

I noticed currentURL() from @ember/test-helpers returns the actual test window address bar URL instead of the test's currentUrl().

I made sure that my ENV.locationType=none. Can someone spot something really obvious that I'm missing?

Expected behavior: when user visits '/clientname', they should be redirected to '/clientname/login':

config/environment.js:

module.exports = function (environment) {
  let ENV = {
    modulePrefix: "portal-client3",
    environment,
    rootURL: "/",
    locationType: "auto",
    EmberENV: {
      FEATURES: {
        // Here you can enable experimental features on an ember canary build
        // e.g. EMBER_NATIVE_DECORATOR_SUPPORT: true
      },
      EXTEND_PROTOTYPES: {
        // Prevent Ember Data from overriding Date.parse.
        Date: false,
      },
    },

    APP: {},
  };

  if (environment === "test") {
    ENV.locationType = "none";
    ENV.APP.LOG_ACTIVE_GENERATION = false;
    ENV.APP.LOG_VIEW_LOOKUPS = false;
    ENV.APP.rootElement = "#ember-testing";
    ENV.APP.autoboot = false;
  }
  return ENV;
};

app/router:

import EmberRouter from "@ember/routing/router";
import config from "./config/environment";

export default class Router extends EmberRouter {
  location = config.locationType;
  rootURL = config.rootURL;
}

tests/test-helper:

import Application from "../app";
import config from "../config/environment";
import { setApplication } from "@ember/test-helpers";
import { start } from "ember-qunit";

setApplication(Application.create(config.APP));
start();

tests/acceptance/login-test:

import { module, test } from "qunit";
import { visit, currentURL } from "@ember/test-helpers";
import { setupApplicationTest } from "ember-qunit";
import { setupMirage } from "ember-cli-mirage/test-support";

module("Acceptance | login", function (hooks) {
  setupApplicationTest(hooks);
  setupMirage(hooks);

  test("visiting /login", async function (assert) {
    await visit("/clientname");
    assert.equal(currentURL(), "/clientname/login");  
    // I see currentUrl()='/tests/login' instead of '/clientname/login'

  });
});

Screenshot: enter image description here

0

There are 0 best solutions below