我注意到currentURL()
从@ember/test-helpers
返回实际的测试窗口地址栏 URL 而不是测试的 currentUrl()。
我确保我的ENV.locationType=none
. 有人能发现我错过的非常明显的东西吗?
预期行为:当用户访问“/clientname”时,他们应该被重定向到“/clientname/login”:
配置/环境.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;
};
应用程序/路由器:
import EmberRouter from "@ember/routing/router";
import config from "./config/environment";
export default class Router extends EmberRouter {
location = config.locationType;
rootURL = config.rootURL;
}
测试/测试助手:
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();
测试/验收/登录测试:
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'
});
});