Skip to content

Commit 930af1e

Browse files
chore(lint): Clean up storage.spec
1 parent 1274627 commit 930af1e

File tree

1 file changed

+34
-30
lines changed

1 file changed

+34
-30
lines changed

src/storage/storage.spec.ts

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { forkJoin } from 'rxjs';
22
import { mergeMap, tap } from 'rxjs/operators';
3-
import { inject, TestBed } from '@angular/core/testing';
3+
import { TestBed } from '@angular/core/testing';
44
import { AngularFireModule, FIREBASE_APP_NAME, FIREBASE_OPTIONS, FirebaseApp } from '@angular/fire';
55
import { AngularFireStorage, AngularFireStorageModule, AngularFireUploadTask, BUCKET } from './public_api';
66
import { COMMON_CONFIG } from '../test-config';
@@ -18,10 +18,9 @@ describe('AngularFireStorage', () => {
1818
AngularFireStorageModule
1919
]
2020
});
21-
inject([FirebaseApp, AngularFireStorage], (app_: FirebaseApp, _storage: AngularFireStorage) => {
22-
app = app_;
23-
afStorage = _storage;
24-
})();
21+
22+
app = TestBed.inject(FirebaseApp);
23+
afStorage = TestBed.inject(AngularFireStorage);
2524
});
2625

2726
afterEach(() => {
@@ -47,35 +46,41 @@ describe('AngularFireStorage', () => {
4746

4847
it('should upload and delete a file', (done) => {
4948
const data = { angular: 'fire' };
50-
const blob = new Blob([JSON.stringify(data)], { type : 'application/json' });
49+
const blob = new Blob([JSON.stringify(data)], { type: 'application/json' });
5150
const ref = afStorage.ref('af.json');
5251
const task = ref.put(blob);
53-
const sub = task.snapshotChanges()
52+
task.snapshotChanges()
5453
.subscribe(
55-
snap => { expect(snap).toBeDefined(); },
56-
e => { done.fail(); },
54+
snap => {
55+
expect(snap).toBeDefined();
56+
},
57+
done.fail,
5758
() => {
5859
ref.delete().subscribe(done, done.fail);
5960
});
6061
});
6162

6263
it('should upload a file and observe the download url', (done) => {
6364
const data = { angular: 'fire' };
64-
const blob = new Blob([JSON.stringify(data)], { type : 'application/json' });
65+
const blob = new Blob([JSON.stringify(data)], { type: 'application/json' });
6566
const ref = afStorage.ref('af.json');
66-
const task = ref.put(blob).then(() => {
67+
ref.put(blob).then(() => {
6768
const url$ = ref.getDownloadURL();
6869
url$.subscribe(
69-
url => { expect(url).toBeDefined(); },
70-
e => { done.fail(); },
71-
() => { ref.delete().subscribe(done, done.fail); }
70+
url => {
71+
expect(url).toBeDefined();
72+
},
73+
done.fail,
74+
() => {
75+
ref.delete().subscribe(done, done.fail);
76+
}
7277
);
7378
});
7479
});
7580

7681
it('should resolve the task as a promise', (done) => {
7782
const data = { angular: 'promise' };
78-
const blob = new Blob([JSON.stringify(data)], { type : 'application/json' });
83+
const blob = new Blob([JSON.stringify(data)], { type: 'application/json' });
7984
const ref = afStorage.ref('af.json');
8085
const task: AngularFireUploadTask = ref.put(blob);
8186
task.then(snap => {
@@ -90,37 +95,37 @@ describe('AngularFireStorage', () => {
9095

9196
it('it should upload, download, and delete', (done) => {
9297
const data = { angular: 'fire' };
93-
const blob = new Blob([JSON.stringify(data)], { type : 'application/json' });
98+
const blob = new Blob([JSON.stringify(data)], { type: 'application/json' });
9499
const ref = afStorage.ref('af.json');
95100
const task = ref.put(blob);
96101
// Wait for the upload
97-
const sub = forkJoin(task.snapshotChanges())
102+
forkJoin([task.snapshotChanges()])
98103
.pipe(
99104
// get the url download
100105
mergeMap(() => ref.getDownloadURL()),
101106
// assert the URL
102107
tap(url => expect(url).toBeDefined()),
103108
// Delete the file
104-
mergeMap(url => ref.delete())
109+
mergeMap(() => ref.delete())
105110
)
106111
// finish the test
107112
.subscribe(done, done.fail);
108113
});
109114

110115
it('should upload, get metadata, and delete', (done) => {
111116
const data = { angular: 'fire' };
112-
const blob = new Blob([JSON.stringify(data)], { type : 'application/json' });
117+
const blob = new Blob([JSON.stringify(data)], { type: 'application/json' });
113118
const ref = afStorage.ref('af.json');
114119
const task = ref.put(blob, { customMetadata: { blah: 'blah' } });
115120
// Wait for the upload
116-
const sub = forkJoin(task.snapshotChanges())
121+
forkJoin([task.snapshotChanges()])
117122
.pipe(
118123
// get the metadata download
119124
mergeMap(() => ref.getMetadata()),
120125
// assert the URL
121126
tap(meta => expect(meta.customMetadata).toEqual({ blah: 'blah' })),
122127
// Delete the file
123-
mergeMap(meta => ref.delete())
128+
mergeMap(() => ref.delete())
124129
)
125130
// finish the test
126131
.subscribe(done, done.fail);
@@ -148,14 +153,13 @@ describe('AngularFireStorage w/options', () => {
148153
],
149154
providers: [
150155
{ provide: FIREBASE_APP_NAME, useValue: firebaseAppName },
151-
{ provide: FIREBASE_OPTIONS, useValue: COMMON_CONFIG },
156+
{ provide: FIREBASE_OPTIONS, useValue: COMMON_CONFIG },
152157
{ provide: BUCKET, useValue: storageBucket }
153158
]
154159
});
155-
inject([FirebaseApp, AngularFireStorage], (app_: FirebaseApp, _storage: AngularFireStorage) => {
156-
app = app_;
157-
afStorage = _storage;
158-
})();
160+
161+
app = TestBed.inject(FirebaseApp);
162+
afStorage = TestBed.inject(AngularFireStorage);
159163
});
160164

161165
afterEach(() => {
@@ -181,26 +185,26 @@ describe('AngularFireStorage w/options', () => {
181185
});
182186

183187
it('storage be pointing towards a different bucket', () => {
184-
expect(afStorage.storage.ref().toString()).toEqual( `gs://${storageBucket}/`);
188+
expect(afStorage.storage.ref().toString()).toEqual(`gs://${storageBucket}/`);
185189
});
186190

187191
// TODO tests for Node?
188192
if (typeof Blob !== 'undefined') {
189193

190194
it('it should upload, download, and delete', (done) => {
191195
const data = { angular: 'fire' };
192-
const blob = new Blob([JSON.stringify(data)], { type : 'application/json' });
196+
const blob = new Blob([JSON.stringify(data)], { type: 'application/json' });
193197
const ref = afStorage.ref('af.json');
194198
const task = ref.put(blob);
195199
// Wait for the upload
196-
const sub = forkJoin(task.snapshotChanges())
200+
forkJoin([task.snapshotChanges()])
197201
.pipe(
198202
// get the url download
199203
mergeMap(() => ref.getDownloadURL()),
200204
// assert the URL
201205
tap(url => expect(url).toMatch(new RegExp(`https:\\/\\/firebasestorage\\.googleapis\\.com\\/v0\\/b\\/${storageBucket}\\/o\\/af\\.json`))),
202206
// Delete the file
203-
mergeMap(url => ref.delete())
207+
mergeMap(() => ref.delete())
204208
)
205209
// finish the test
206210
.subscribe(done, done.fail);

0 commit comments

Comments
 (0)