我正在针对具有管理和非管理功能的路由编写一个非常基本的验收测试。我的测试断言,如果我是第一次使用该应用程序,则看不到已登录的功能。在我的应用程序中,我使用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
在仔细查看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-adapter解决我使用应用程序时可能拥有的任何会话数据。然后,我可以使用提供的torii帮助程序在需要的地方模拟我的会话:
// torii helper
import { stubValidSession } from 'app/tests/helpers/torii';
// mock a valid session
stubValidSession(application, { });
希望可以节省其他人的时间。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句