Eas*_*yCo 1 phantomjs ember.js ember-cli ember-simple-auth
我让 ESA 与 Ember 2.0.1 配合良好,但在测试时偶然发现了一个有趣的案例:
给出以下测试:
import Ember from 'ember';
import { module, test } from 'qunit';
import startApp from 'notifier/tests/helpers/start-app';
import Pretender from 'pretender';
import { authenticateSession } from '../../helpers/ember-simple-auth';
let server;
let application;
module('Acceptance | signout', {
beforeEach: function() {
application = startApp();
},
afterEach: function() {
Ember.run(application, 'destroy');
server.shutdown();
}
});
test('successfully sign out and get redirected', function(assert) {
server = new Pretender(function() {
this.post('/oauth/revoke', function() {
return [200, {"Content-Type": "application/json"}];
});
});
authenticateSession(application);
visit('/admin');
click('#sign-out');
andThen(() => {
assert.equal(currentRouteName(), 'users.sign-in');
});
});
Run Code Online (Sandbox Code Playgroud)
测试结果是路线永远不会改变。它保持打开状态/admin。这仅发生在测试中,如果我手动与应用程序交互,它就可以正常工作。
发生这种情况的原因是,window.location.reload()根据https://github.com/simplabs/ember-simple-auth/blob/jj-abrams/addon/mixins/application-route-mixin ,会话失效后页面永远不会重新加载 ( ) .js#L99-L101 .
因此beforeModel 钩子永远AuthenticatedRouteMixin不会被触发,因此测试永远不会重定向/admin到/users/sign-in。
我知道发生这种情况是因为您无法window.location.reload()在测试中运行,但我不确定该使用什么替代方案。我可以sessionInvalidated()在我的应用程序路由中进行覆盖,并在测试时将应用程序重定向到/users/sign-in,但这不再是实际测试我认为的应用程序。
有什么建议么?
| 归档时间: |
|
| 查看次数: |
1173 次 |
| 最近记录: |