应用路线失败的灰烬单元测试

时间:2016-08-22 19:22:43

标签: ember.js

我是一个余烬。我已经回顾了Ember教程中的步骤,并采取了非常温和的方式来添加带有身份验证流程的bootstrap。在某处我添加了应用程序路径。发电机做了这个:

import { moduleFor, test } from 'ember-qunit';

moduleFor('route:application', 'Unit | Route | application', {
  // Specify the other units that are required for this test.
  // needs: ['controller:foo']
});

test('it exists', function(assert) {
  let route = this.subject();
  assert.ok(route);
});

app / routes / application.js看起来像:

import Ember from 'ember';
import ApplicationRouteMixin from 'ember-simple-auth/mixins/application-route-mixin';

export default Ember.Route.extend(ApplicationRouteMixin);

这是轰炸。我做了一些调查,但我太新了,无法在下面的堆栈跟踪中找到我的悲惨原因。我当然可以吹掉错误,但我觉得我将再次犯同样的错误,并且不想削弱测试用例。有谁知道我在application-test.js中缺少什么?

Unit | Route | application: it exists (1, 0, 1)Rerun39 ms
Died on test #1     at testWrapper (http://localhost:7357/assets/test-support.js:7162:11)
    at test (http://localhost:7357/assets/test-support.js:7176:39)
    at Module.callback (http://localhost:7357/assets/tests.js:367:24)
    at Module.exports (http://localhost:7357/assets/vendor.js:132:32)
    at requireModule (http://localhost:7357/assets/vendor.js:32:18)
    at Object.TestLoader.require (http://localhost:7357/assets/test-support.js:6942:7)
    at Object.loadModules (http://localhost:7357/assets/test-support.js:6934:14): Cannot read property 'on' of undefined@ 22 ms
Source:     
TypeError: Cannot read property 'on' of undefined
    at http://localhost:7357/assets/vendor.js:151286:29
    at Array.forEach (native)
    at Class._subscribeToSessionEvents (http://localhost:7357/assets/vendor.js:151280:131)
    at Class.init (http://localhost:7357/assets/vendor.js:151273:12)
    at Class.superWrapper [as init] (http://localhost:7357/assets/vendor.js:35502:22)
    at new Class (http://localhost:7357/assets/vendor.js:48214:14)
    at Function.create (http://localhost:7357/assets/vendor.js:48485:14)
    at Object.defaultSubject (http://localhost:7357/assets/test-support.js:8362:22)
    at Object.context.(anonymous function) [as subject] (http://localhost:7357/assets/test-support.js:8394:37)
    at Object.<anonymous> (http://localhost:7357/assets/tests.js:368:22)
Source: at testWrapper (http://localhost:7357/assets/test-support.js:7162:11) at test (http://localhost:7357/assets/test-support.js:7176:39) at Module.callback (http://localhost:7357/assets/tests.js:367:24) at Module.exports (http://localhost:7357/assets/vendor.js:132:32) at requireModule (http://localhost:7357/assets/vendor.js:32:18) at Object.TestLoader.require (http://localhost:7357/assets/test-support.js:6942:7) at Object.loadModules (http://localhost:7357/assets/test-support.js:6934:14)

1 个答案:

答案 0 :(得分:0)

在不知道您的申请路线在做什么的情况下,我无法确定,但这里有几种可能性:

看起来有一些代码在没有定义的对象上调用jquery。

您可以导入尚未用于测试的第三方库(例如,如果您已在index.html中添加了脚本),或者您可能具有特定于环境的资产(https://guides.emberjs.com/v2.7.0/addons-and-dependencies/managing-dependencies/#toc_environment-specific-assets

您还可能需要在您的&#34;需求&#34;中包含依赖项。块。通常从容器中加载的内容(如ember数据对象,服务和控制器)需要在需求块中指定以进行单元测试。