【问题标题】:Ember.js - Acceptance tests UnrecognizedURLError: /testsEmber.js - 验收测试 UnrecognizedURLError: /tests
【发布时间】:2019-08-12 23:55:38
【问题描述】:

最近将 Ember CLI 从 2.15.0 迁移到 3.7.0,验收测试已经严重退步。运行qunit codemod 后,似乎仍然存在以下问题:UnrecognizedURLError: /tests

我已通过以下验收测试对问题进行了最低限度的复制:

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/setup-mirage';


module('Acceptance | poc', function(hooks) {
  setupApplicationTest(hooks);
  setupMirage(hooks);

  test('visiting /poc', async function(assert) {
    await visit('/');

    assert.equal(currentURL(), '/');
  });
});

这导致以下三个问题:

Promise rejected before "visiting /poc": /tests?filter=poc
Source:     UnrecognizedURLError: /tests?filter=poc 
beforeEach failed on visiting /poc: You must call one of the ember-qunit setupTest(), setupRenderingTest() or setupApplicationTest() methods before calling setupMirage()
Source:     Error: You must call one of the ember-qunit setupTest(), setupRenderingTest() or setupApplicationTest() methods before calling setupMirage()
Promise rejected after "visiting /poc": Cannot use 'in' operator to search for 'destroy' in undefined@ 80 ms
Source:     TypeError: Cannot use 'in' operator to search for 'destroy' in undefined

任何建议将不胜感激!

【问题讨论】:

  • 网址/poc是否存在?
  • 你是@ember/test-helpersember-qunit 的哪个版本?
  • @rinoldsimon 测试不是指向/poc,而是指向根/ 路由
  • @mistahenry 我正在使用"ember-cli-qunit": "^4.4.0","@ember/test-helpers": "^1.5.0",
  • locationType 在测试环境中长期设置为none 在ember 的默认蓝图中:github.com/ember-cli/ember-new-output/blob/master/config/… 实际上是因为ember-cli 的0.1.3。我建议还将测试环境的运行时配置与 ember 新输出进行比较。您可能还会错过新测试 API 所需的 ENV.autoboot = false

标签: ember.js qunit acceptance-testing ember-cli-mirage


【解决方案1】:

正如@jelhan 在上面的评论中指出的那样,这里的问题是environment.js 配置中缺少test 环境设置。

修复UnrecognizedURLError,添加ENV.locationType = 'none'即可满足testem的要求。

我还替换了链接的block 中的其他环境变量。

我的测试环境配置现在如下所示:

else 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;
  }

【讨论】:

    猜你喜欢
    • 2015-11-14
    • 1970-01-01
    • 1970-01-01
    • 2018-01-19
    • 2011-04-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多