ember-cli测试:拆解失败:无法读取未定义的属性'unchain'

时间:2014-06-26 08:01:37

标签: ember.js qunit ember-cli

我正在尝试为ember-cli app编写一个简单的测试:

import startApp from 'wallet2/tests/helpers/start-app';

var App;

module('integration - login', {
  setup: function() {
    App = startApp()
  },
  teardown: function() {
    Ember.run(App, "destroy");
  }
});

test('Should ask me to log in', function() {
  visit('/').then(function() {
    equal(find('h1#title').text(), 'Please login');
    equal(find('form').length, 1);
  });
});

测试通过但是拆解失败了:

Teardown failed on Should ask me to log in: Cannot read property 'unchain' of undefined
Source:     
    at ChainNodePrototype.unchain (http://localhost:4200/assets/vendor.js:17359:9)
    at ChainNodePrototype.remove (http://localhost:4200/assets/vendor.js:17331:8)
    at Ember.unwatchPath (http://localhost:4200/assets/vendor.js:17550:23)
    at Object.Ember.unwatch (http://localhost:4200/assets/vendor.js:17619:5)
    at Object.Ember.removeObserver (http://localhost:4200/assets/vendor.js:19031:9)
    at null.<anonymous> (http://localhost:4200/assets/vendor.js:37793:13)
    at Object.sendEvent (http://localhost:4200/assets/vendor.js:15748:14)
    at Ember.Evented.Ember.Mixin.create.trigger (http://localhost:4200/assets/vendor.js:31468:11)
    at superFunction [as _super] (http://localhost:4200/assets/vendor.js:20874:16)
    at Ember.CoreView.Ember.Object.extend.trigger (http://localhost:4200/assets/vendor.js:35658:17)

我无法找到导致问题的原因。

这是我的start-app.js

var Application = require('wallet2/app')['default'];
var Router = require('wallet2/router')['default'];

export default function startApp(attrs) {
  var App;

  var attributes = Ember.merge({
    // useful Test defaults
    rootElement: '#ember-testing',
    LOG_ACTIVE_GENERATION:false,
    LOG_VIEW_LOOKUPS: false
  }, attrs); // but you can override;

  Router.reopen({
    location: 'none'
  });

  Ember.run(function(){
    App = Application.create(attributes);
    App.setupForTesting();
    App.injectTestHelpers();
  });

  App.reset(); // this shouldn't be needed, i want to be able to "start an app at a specific URL"

  return App;
}

非常感谢任何帮助......

更新(2014-07-07)

这是我访问&#34; /&#34;时调用的routes / index.js (&#39; m使用ember-simple-auth)

import Ember from 'ember';
import AuthenticatedRouteMixin from 'simple-auth/mixins/authenticated-route-mixin';
export default Ember.Route.extend( AuthenticatedRouteMixin, {
  redirect: function (params) {
    this.transitionTo("users.show", this.get('session.user'));
  }
});

controllers / login.js

import Ember from 'ember';
import LoginControllerMixin from 'simple-auth/mixins/login-controller-mixin';

export default Ember.Controller.extend( LoginControllerMixin, {
  authenticator: 'simple-auth-authenticator:devise'
});

和login.hbs模板:

<div class="row">
  <div class="col-xs-12 col-sm-6 col-sm-offset-3">
    <h1 id="title">Please login</h1>
    <form {{action 'authenticate' on='submit'}} role="form">
      <div class="form-group">
        {{input id='identification' type="email" class="form-control" placeholder='Email' value=identification}}
      </div>
      <div class="form-group">
        {{input id='password' class="form-control" placeholder='Password' type='password' value=password}}
      </div>
      <button class="btn btn-default" type="submit">Login</button>
    </form>
  </div>
  <div class="col-xs-12 col-sm-6 col-sm-offset-3">
    <p class="top">
      {{#link-to "users.reset_password"}}Did you forget your password?{{/link-to}}
    <p>
  </div>
</div>

3 个答案:

答案 0 :(得分:0)

你试过吗

Ember.run(App, App.destroy);

而不是

Ember.run(App, "destroy");

答案 1 :(得分:0)

将测试更改为

test('Should ask me to log in', function() {
  visit('/')
    .find('h1#title')
    .then(function(title){
      equal(title.text(), 'Please login');
    })
    .find('form')
    .then(function(form){
      equal(form.length, 1, 'Form added to DOM');
    });
});

答案 2 :(得分:0)

在我覆盖特定函数并且没有调用this._super()之前,我已经看到过这种类型的错误。你可以这样做吗?