我让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');
  });
});
  
   测试结果是路线从未改变。它保持打开状态
   
    /admin
   
   。这只发生在测试中,如果我手动与应用程序交互,它会正常工作。
  
  
   发生这种情况的原因是页面从未重新加载(
   
    window.location.reload()
   
   )在会话根据
   
    https://github.com/simplabs/ember-simple-auth/blob/jj-abrams/addon/mixins/application-route-mixin.js#L99-L101
   
   .
  
  
   因此
   
    beforeModel hook
   
   在里面
   
    AuthenticatedRouteMixin
   
   永远不会被触发,所以测试永远不会重定向到
   
    /管理员
   
   到
   
    /users/sign-in
   
   .
  
  
   我知道这是因为你不能跑
   
    window.location.reload()
   
   但我不知道该用什么替代品。我可以超越
   
    sessionInvalidated()
   
   在我的应用程序路径中,只需将应用程序重定向到
   
    /用户/登录
   
   测试时,但我想这已经不再是实际测试应用程序了。
  
  
   有什么建议吗?