找不到变量:invalidateSession使用ember-cli-simple-auth-testing

时间:2015-05-24 12:03:18

标签: ember.js ember-simple-auth

我正在使用ember-cli-simple-auth并使用ember-cli-simple-auth-testing进行测试。我按照README安装了测试库。

tests/helpers/start-app.js包含:

import Ember from 'ember';
import Application from '../../app';
import Router from '../../router';
import config from '../../config/environment';

import 'simple-auth-testing/test-helpers';

export default function startApp(attrs) {
  var application;

  var attributes = Ember.merge({}, config.APP);
  attributes = Ember.merge(attributes, attrs); // use defaults, but you can override;

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

  return application;
}

config/environment.js包含:

...
if (environment === 'test') {
  // Testem prefers this...
  ENV.baseURL = '/';
  ENV.locationType = 'none';

  // keep test console output quieter
  ENV.APP.LOG_ACTIVE_GENERATION = false;
  ENV.APP.LOG_VIEW_LOOKUPS = false;

  ENV.APP.rootElement = '#ember-testing';

  ENV['simple-auth'] = {
    store: 'simple-auth-session-store:ephemeral'
  }
}
...

当我在测试中调用invalidateSession()时,出现以下错误:

Acceptance | items: the route /items is inaccessible when the session is not authenticated
✘ Died on test #1     at http://localhost:7357/assets/test-support.js:2688
    at http://localhost:7357/assets/wishlist.js:2055
    at http://localhost:7357/assets/vendor.js:150
    at tryFinally (http://localhost:7357/assets/vendor.js:30)
    at http://localhost:7357/assets/vendor.js:156
    at http://localhost:7357/assets/test-loader.js:29
    at http://localhost:7357/assets/test-loader.js:21
    at http://localhost:7357/assets/test-loader.js:40
    at http://localhost:7357/assets/test-support.js:5460: Can't find variable: invalidateSession

我一定做错了。它是什么?

1 个答案:

答案 0 :(得分:0)

0.8.0-beta.2的正确导入是:

import initializeTestHelpers from 'simple-auth-testing/test-helpers';
initializeTestHelpers();

export default function startApp(attrs) {