forked from angular/angularfire
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.spec.ts
More file actions
121 lines (97 loc) · 3.49 KB
/
database.spec.ts
File metadata and controls
121 lines (97 loc) · 3.49 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import { AngularFireModule, FIREBASE_APP_NAME, FIREBASE_OPTIONS, FirebaseApp } from '@angular/fire';
import { AngularFireDatabase, AngularFireDatabaseModule, URL } from './public_api';
import { TestBed } from '@angular/core/testing';
import { COMMON_CONFIG } from '../test-config';
import { NgZone } from '@angular/core';
import 'firebase/database';
import { rando } from '../firestore/utils.spec';
describe('AngularFireDatabase', () => {
let app: FirebaseApp;
let db: AngularFireDatabase;
let zone: NgZone;
let firebaseAppName: string;
beforeEach(() => {
firebaseAppName = rando();
TestBed.configureTestingModule({
imports: [
AngularFireModule.initializeApp(COMMON_CONFIG, firebaseAppName),
AngularFireDatabaseModule
],
providers: [
{ provide: URL, useValue: 'http://localhost:9000' }
]
});
app = TestBed.inject(FirebaseApp);
db = TestBed.inject(AngularFireDatabase);
zone = TestBed.inject(NgZone);
});
afterEach(() => {
app.delete();
});
describe('<constructor>', () => {
it('should be an AngularFireDatabase type', () => {
expect(db instanceof AngularFireDatabase).toEqual(true);
});
it('should have an initialized Firebase app', () => {
expect(db.database.app).toBeDefined();
});
it('should accept a Firebase App in the constructor', (done) => {
const database = new AngularFireDatabase(app.options, rando(), undefined, {}, zone, undefined, undefined);
expect(database instanceof AngularFireDatabase).toEqual(true);
database.database.app.delete().then(done, done);
});
it('should have an initialized Firebase app instance member', () => {
expect(db.database.app.name).toEqual(firebaseAppName);
});
});
});
describe('AngularFireDatabase w/options', () => {
let app: FirebaseApp;
let db: AngularFireDatabase;
let firebaseAppName: string;
let url: string;
let query: string;
beforeEach(() => {
query = rando();
firebaseAppName = rando();
url = `http://localhost:${Math.floor(Math.random() * 9999)}`;
TestBed.configureTestingModule({
imports: [
AngularFireModule.initializeApp(COMMON_CONFIG, rando()),
AngularFireDatabaseModule
],
providers: [
{ provide: FIREBASE_APP_NAME, useValue: firebaseAppName },
{ provide: FIREBASE_OPTIONS, useValue: COMMON_CONFIG },
{ provide: URL, useValue: url }
]
});
app = TestBed.inject(FirebaseApp);
db = TestBed.inject(AngularFireDatabase);
});
afterEach(() => {
app.delete();
});
describe('<constructor>', () => {
it('should be an AngularFireDatabase type', () => {
expect(db instanceof AngularFireDatabase).toEqual(true);
});
it('should have an initialized Firebase app', () => {
expect(db.database.app).toBeDefined();
});
it('should have an initialized Firebase app instance member', () => {
expect(db.database.app.name).toEqual(firebaseAppName);
});
/* INVESTIGATE database(url) does not seem to be working
it('database be pointing to the provided DB instance', () => {
expect(db.database.ref().toString()).toEqual(url);
});
it('list should be using the provided DB instance', () => {
expect(db.list(query).query.toString()).toEqual(`${url}/${query}`);
});
it('object should be using the provided DB instance', () => {
expect(db.object(query).query.toString()).toEqual(`${url}/${query}`);
});
*/
});
});