我正在尝试测试我的注册和登录过程,集成测试在创建初始化程序以使用 currentUser 属性扩展 Ember-Simple-Auth Session 对象之前完美通过。
这一切都在浏览器中正常工作,只是测试现在在以下行的应用程序路由中的 sessionAuthenticationSucceeded 操作中全部失败:
this.get('session.currentUser').then(function(user) {
与:TypeError:无法读取未定义的属性'then'
/routes/application.js
import Ember from 'ember';
import ApplicationRouteMixin from 'simple-auth/mixins/application-route-mixin';
export default Ember.Route.extend(ApplicationRouteMixin, {
actions: {
sessionAuthenticationSucceeded: function () {
var self = this;
this.get('session.currentUser').then(function(user) {
if (user.get('account') && user.get('status') === 'complete'){
self.transtionTo('home');
} else {
console.log('Need to complete Registration');
self.transitionTo('me');
}
});
}
}
}
/initializers/custom-session.js
import Ember from 'ember';
import Session from 'simple-auth/session';
export default {
name: 'custom-session',
before: 'simple-auth',
initialize: function(container) {
// application.deferReadiness();
Session.reopen({
currentUser: function() {
var id = this.get('user_id');
if (!Ember.isEmpty(id)) {
console.log('getting the current user');
return container.lookup('store:main').find('user', id);
}
}.property('user_id')
});
// application.advanceReadiness();
}
};
/tests/integration/visitor-signs-up-test.js
test('As a user with valid email and password', function(){
var email = faker.internet.email();
signUpUser(email, 'correctpassword', 'correctpassword');
andThen(function(){
equal(find('#logged-in-user').text(), email, 'User registered successfully as ' + email);
equal(sessionIsAuthenticated(App), true, 'The session is Authenticated');
});
});
测试/helpers/registration-login.js
export function signUpUser(email, password, passwordConfirmation) {
visit('/register').then(function(){
fillIn('input.email', email);
fillIn('input.password', password);
fillIn('input.password-confirmation', passwordConfirmation);
click('button.submit');
});
}
我试过使用
application.deferReadiness()
如您所见,在初始化程序中已注释掉(也在该实例中传递应用程序)以确保异步请求已完成并且用户可用,但这也不起作用。
我正在使用Pretenderapi/v1/users/:id
拦截 api 请求,但在测试期间根本没有调用。
奇怪的是它在浏览器中完美运行。
我试图理解为什么这不起作用?任何指导将不胜感激!