我正在尝试为 ember-cli 应用程序编写一个简单的测试:
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;
}
任何帮助将不胜感激……</p> 更新 (2014-07-07)
这是我在访问“/”时调用的 routes/index.js(我使用的是 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'));
}
});
控制器/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>