-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
Copy pathangularfire2.spec.ts
75 lines (64 loc) · 2.36 KB
/
angularfire2.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import { TestBed, inject, withModule, async } from '@angular/core/testing';
import { ReflectiveInjector, Provider, PlatformRef, NgModule, Compiler, ApplicationRef, CompilerFactory } from '@angular/core';
import { FirebaseApp, AngularFireModule } from 'angularfire2';
import { Subscription } from 'rxjs';
import { COMMON_CONFIG } from './test-config';
import { BrowserModule } from '@angular/platform-browser';
import { database } from 'firebase/app';
describe('angularfire', () => {
let subscription:Subscription;
let app: FirebaseApp;
let rootRef: database.Reference;
let questionsRef: database.Reference;
let listOfQuestionsRef: database.Reference;
let defaultPlatform: PlatformRef;
const APP_NAME = 'super-awesome-test-firebase-app-name';
beforeEach(() => {
TestBed.configureTestingModule({
imports: [AngularFireModule.initializeApp(COMMON_CONFIG, APP_NAME)]
});
inject([FirebaseApp, PlatformRef], (_app: FirebaseApp, _platform: PlatformRef) => {
app = _app;
rootRef = app.database!().ref();
questionsRef = rootRef.child('questions');
listOfQuestionsRef = rootRef.child('list-of-questions');
defaultPlatform = _platform;
})();
});
afterEach((done) => {
rootRef.remove()
if(subscription && !subscription.closed) {
subscription.unsubscribe();
}
app.delete().then(done, done.fail);
});
describe('FirebaseApp', () => {
it('should provide a FirebaseApp for the FirebaseApp binding', () => {
expect(typeof app.delete).toBe('function');
});
it('should have the provided name', () => {
expect(app.name).toBe(APP_NAME);
})
it('should use an already intialized firebase app if it exists', done => {
@NgModule({
imports: [
AngularFireModule.initializeApp(COMMON_CONFIG, APP_NAME),
BrowserModule
]})
class MyModule {
ngDoBootstrap() {}
}
const compilerFactory: CompilerFactory =
defaultPlatform.injector.get(CompilerFactory, null);
const moduleFactory = compilerFactory.createCompiler().compileModuleSync(MyModule);
defaultPlatform.bootstrapModuleFactory(moduleFactory)
.then(moduleRef => {
const ref = moduleRef.injector.get(FirebaseApp);
expect(ref.name).toEqual(app.name);
}).then(done, e => {
fail(e);
done()
});
})
});
});