代码之家  ›  专栏  ›  技术社区  ›  dpigera

余烬辛烷值测试:env.位置类型不工作

  •  0
  • dpigera  · 技术社区  · 6 年前

    我注意到了 currentURL() 从 @ember/test-helpers 返回实际的测试窗口地址栏URL,而不是测试的currentUrl()。

    我确保我的 ENV.locationType=none 有人能发现我遗漏的一些非常明显的东西吗?

    预期行为:当用户访问“/clientname”时,应将其重定向到“/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;
    };
    

    应用程序/路由器:

    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'
    
      });
    });
    
    

    截图: enter image description here

    0 回复  |  直到 6 年前
    推荐文章