我正在针对具有管理和非管理功能的路由编写一个非常基本的验收测试。我的测试断言,如果我第一次访问这个应用程序,我看不到登录功能。在我的应用程序中,我使用password身份验证,如下所示:
this.get('session').open('firebase', {
provider: 'password',
email: email,
password: password
});我发现,当我没有在应用程序认证,然后运行验收测试,它通过。但是,如果我随后登录应用程序,然后运行测试,我的断言就会失败,因为会话被恢复了,而我认为它不应该恢复。下面是一个测试:
import { test } from 'qunit';
import moduleForAcceptance from 'app/tests/helpers/module-for-acceptance';
import startApp from '../helpers/start-app';
import destroyApp from '../helpers/destroy-app';
import replaceAppRef from '../helpers/replace-app-ref';
import replaceFirebaseAppService from '../helpers/replace-firebase-app-service';
import stubFirebase from '../helpers/stub-firebase';
import unstubFirebase from '../helpers/unstub-firebase';
import { emptyApplication } from '../helpers/create-test-ref';
moduleForAcceptance('Acceptance | index', {
beforeEach: function() {
stubFirebase();
application = startApp();
replaceFirebaseAppService(application, { });
replaceAppRef(application, emptyApplication());
},
afterEach: function() {
unstubFirebase();
destroyApp(application);
}
});
test('empty app - not authenticated', function(assert) {
visit('/');
andThen(function() {
assert.equal(currentURL(), page.url, 'on the correct page');
// this works if there's no session - fails otherwise
assert.notOk(page.something.isVisible, 'cannot do something');
});
});我认为replaceFirebaseAppService应该覆盖torii-adapter,但看起来并非如此。任何帮助都将不胜感激。
我在用:
Ember : 2.7.0
Ember Data : 2.7.0
Firebase : 3.2.1
EmberFire : 2.0.1
jQuery : 2.2.4发布于 2016-08-14 13:11:38
仔细看看Emberfire,replaceFirebaseAppService正在尝试替换torii-adapter:firebase注册的torii适配器,当时它正被我的应用程序注册为torii-adapter:application。
我最后所做的基本上是在我自己的助手中复制replaceFirebaseAppService:
import stubFirebase from '../helpers/stub-firebase';
import startApp from '../helpers/start-app';
import replaceAppRef from '../helpers/replace-app-ref';
import createOfflineRef from './create-offline-ref';
export default function startFirebaseApp(fixtures = { }) {
stubFirebase();
let application = startApp();
// override default torii-adapter
const mock = { };
application.register('service:firebaseMock', mock, {
instantiate: false,
singleton: true
});
application.inject('torii-provider:application', 'firebaseApp', 'service:firebaseMock');
application.inject('torii-adapter:application', 'firebaseApp', 'service:firebaseMock');
// setup any fixture data and return instance
replaceAppRef(application, createOfflineRef(fixtures));
return application;
}这就阻止了torii适配器解析我使用应用程序时可能拥有的任何会话数据。然后,我可以使用提供的torii助手来模拟我需要的会话:
// torii helper
import { stubValidSession } from 'app/tests/helpers/torii';
// mock a valid session
stubValidSession(application, { });希望这能给别人省点时间。
https://stackoverflow.com/questions/38907795
复制相似问题