diff --git a/karma-test-shim.js b/karma-test-shim.js index 184fb51d2..d1bf56928 100644 --- a/karma-test-shim.js +++ b/karma-test-shim.js @@ -30,35 +30,31 @@ System.config({ System.config( { + paths: { + // paths serve as alias + 'npm:': 'node_modules/' + }, map: { - 'rxjs': 'node_modules/rxjs', - '@angular': 'node_modules/@angular', - firebase: 'node_modules/firebase/firebase.js', - 'app': 'dist' + 'app': 'dist', + '@angular/core': 'npm:@angular/core/bundles/core.umd.js', + '@angular/common': 'npm:@angular/common/bundles/common.umd.js', + '@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js', + '@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js', + '@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js', + + // angular testing umd bundles + '@angular/core/testing': 'npm:@angular/core/bundles/core-testing.umd.js', + '@angular/common/testing': 'npm:@angular/common/bundles/common-testing.umd.js', + '@angular/compiler/testing': 'npm:@angular/compiler/bundles/compiler-testing.umd.js', + '@angular/platform-browser/testing': 'npm:@angular/platform-browser/bundles/platform-browser-testing.umd.js', + '@angular/platform-browser-dynamic/testing': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic-testing.umd.js', + + // other libraries + 'rxjs': 'npm:rxjs', + 'firebase': 'npm:firebase/firebase.js' }, packages: { 'app': { - main: 'main.js', - defaultExtension: 'js' - }, - '@angular/core': { - main: 'index.js', - defaultExtension: 'js' - }, - '@angular/compiler': { - main: 'index.js', - defaultExtension: 'js' - }, - '@angular/common': { - main: 'index.js', - defaultExtension: 'js' - }, - '@angular/platform-browser': { - main: 'index.js', - defaultExtension: 'js' - }, - '@angular/platform-browser-dynamic': { - main: 'index.js', defaultExtension: 'js' }, 'rxjs': { @@ -75,8 +71,10 @@ Promise.all([ var testing = providers[0]; var testingBrowser = providers[1]; - testing.setBaseTestProviders(testingBrowser.TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS, - testingBrowser.TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS); + testing.TestBed.initTestEnvironment( + testingBrowser.BrowserDynamicTestingModule, + testingBrowser.platformBrowserDynamicTesting() + ); }).then(function() { // Finally, load all spec files. diff --git a/karma.conf.js b/karma.conf.js index 39a4c1917..36f0bf4d8 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -18,25 +18,27 @@ module.exports = function(config) { // Zone.js dependencies 'node_modules/zone.js/dist/zone.js', + 'node_modules/zone.js/dist/proxy.js', + 'node_modules/zone.js/dist/sync-test.js', 'node_modules/zone.js/dist/jasmine-patch.js', 'node_modules/zone.js/dist/async-test.js', + 'node_modules/zone.js/dist/fake-async-test.js', // RxJs. { pattern: 'node_modules/rxjs/**/*.js', included: false, watched: false }, { pattern: 'node_modules/rxjs/**/*.js.map', included: false, watched: false }, - {pattern: 'karma-test-shim.js', included: true, watched: true}, - {pattern: 'built/test/matchers.js', included: true, watched: true}, + { pattern: 'karma-test-shim.js', included: true, watched: true }, // paths loaded via module imports // Angular itself - {pattern: 'node_modules/@angular/**/*.js', included: false, watched: true}, - {pattern: 'node_modules/@angular/**/*.js.map', included: false, watched: true}, + { pattern: 'node_modules/@angular/**/*.js', included: false, watched: true }, + { pattern: 'node_modules/@angular/**/*.js.map', included: false, watched: true }, - {pattern: 'node_modules/firebase/firebase.js', included: false, watched: false}, - {pattern: 'dist/**/*.js', included: false, watched: true}, - {pattern: 'dist/**/*.js.map', included: false, watched: false} + { pattern: 'node_modules/firebase/firebase.js', included: false, watched: false }, + { pattern: 'dist/**/*.js', included: false, watched: true }, + { pattern: 'dist/**/*.js.map', included: false, watched: false } ], port: 9876, diff --git a/package.json b/package.json index 31f4ccaeb..572259cb8 100644 --- a/package.json +++ b/package.json @@ -32,13 +32,14 @@ }, "homepage": "https://github.com/angular/angularfire2#readme", "dependencies": { - "@angular/common": "^2.0.0-rc.5", - "@angular/compiler": "^2.0.0-rc.5", - "@angular/core": "^2.0.0-rc.5", - "@angular/platform-browser": "^2.0.0-rc.5", - "@angular/platform-browser-dynamic": "^2.0.0-rc.5", - "firebase": "^3.0.3", - "rxjs": "5.0.0-beta.6" + "@angular/common": "^2.0.0-rc.7", + "@angular/compiler": "^2.0.0-rc.7", + "@angular/core": "^2.0.0-rc.7", + "@angular/platform-browser": "^2.0.0-rc.7", + "@angular/platform-browser-dynamic": "^2.0.0-rc.7", + "@types/request": "0.0.30", + "firebase": "3.3.0", + "rxjs": "5.0.0-beta.12" }, "devDependencies": { "@angular/compiler-cli": "^0.5.0", @@ -70,7 +71,7 @@ "typedoc": "github:jeffbcross/typedoc", "typescript": "next", "typings": "^1.3.2", - "zone.js": "^0.6.6" + "zone.js": "^0.6.21" }, "typings": "dist/angularfire2.d.ts" } diff --git a/src/angularfire2.spec.ts b/src/angularfire2.spec.ts index dbe0d14ba..d745e2d73 100644 --- a/src/angularfire2.spec.ts +++ b/src/angularfire2.spec.ts @@ -1,8 +1,8 @@ import { - addProviders, + TestBed, inject } from '@angular/core/testing'; -import { ReflectiveInjector, provide, Provider } from '@angular/core'; +import { ReflectiveInjector, Provider } from '@angular/core'; import { AngularFire, FirebaseObjectObservable, @@ -12,21 +12,16 @@ import { FirebaseApp, defaultFirebase, AngularFireDatabase, - FirebaseAppConfig + FirebaseAppConfig, + AngularFireModule } from './angularfire2'; import { Subscription } from 'rxjs/Subscription'; +import { COMMON_CONFIG, ANON_AUTH_CONFIG } from './test-config'; import 'rxjs/add/operator/toPromise'; import 'rxjs/add/operator/take'; import 'rxjs/add/operator/do'; import 'rxjs/add/operator/delay'; -export const firebaseConfig: FirebaseAppConfig = { - apiKey: "AIzaSyBVSy3YpkVGiKXbbxeK0qBnu3-MNZ9UIjA", - authDomain: "angularfire2-test.firebaseapp.com", - databaseURL: "https://angularfire2-test.firebaseio.com", - storageBucket: "angularfire2-test.appspot.com", -}; - describe('angularfire', () => { var subscription:Subscription; var app: firebase.app.App; @@ -36,7 +31,11 @@ describe('angularfire', () => { var angularFire2: AngularFire; beforeEach(() => { - addProviders([FIREBASE_PROVIDERS, defaultFirebase(firebaseConfig)]); + + TestBed.configureTestingModule({ + imports: [AngularFireModule.initializeApp(COMMON_CONFIG, ANON_AUTH_CONFIG)] + }); + inject([FirebaseApp, AngularFire], (firebaseApp: firebase.app.App, _af: AngularFire) => { angularFire2 = _af; app = firebaseApp; @@ -48,7 +47,7 @@ describe('angularfire', () => { afterEach((done) => { rootRef.remove() - if(subscription && !subscription.isUnsubscribed) { + if(subscription && !subscription.closed) { subscription.unsubscribe(); } app.delete().then(done, done.fail); @@ -80,7 +79,7 @@ describe('angularfire', () => { describe('defaultFirebase', () => { it('should create an array of providers', () => { - const providers = defaultFirebase(firebaseConfig); + const providers = defaultFirebase(COMMON_CONFIG); expect(providers.length).toBe(2); }); }); diff --git a/src/angularfire2.ts b/src/angularfire2.ts index 3747748ac..cbc01fa75 100644 --- a/src/angularfire2.ts +++ b/src/angularfire2.ts @@ -18,7 +18,6 @@ import { Inject, Injectable, OpaqueToken, - provide, NgModule, ModuleWithProviders } from '@angular/core'; @@ -44,7 +43,7 @@ import { @Injectable() export class AngularFire { constructor( - @Inject(FirebaseConfig) private fbUrl:string, + @Inject(FirebaseConfig) private firebaseConfig:string, public auth: AngularFireAuth, public database: AngularFireDatabase) {} } diff --git a/src/auth/auth.spec.ts b/src/auth/auth.spec.ts index a4a6a705c..89fe0e6f6 100644 --- a/src/auth/auth.spec.ts +++ b/src/auth/auth.spec.ts @@ -1,9 +1,9 @@ import { auth, initializeApp } from 'firebase'; -import { ReflectiveInjector, provide, Provider } from '@angular/core'; +import { ReflectiveInjector, Provider } from '@angular/core'; import { Observable } from 'rxjs/Observable' import { Observer } from 'rxjs/Observer'; import { - addProviders, + TestBed, inject } from '@angular/core/testing'; import 'rxjs/add/operator/do'; @@ -19,9 +19,10 @@ import { AuthMethods, firebaseAuthConfig, AuthProviders, - WindowLocation + WindowLocation, + AngularFireModule } from '../angularfire2'; -import { COMMON_CONFIG } from '../test-config'; +import { COMMON_CONFIG, ANON_AUTH_CONFIG } from '../test-config'; import { AuthBackend } from './auth_backend'; import { FirebaseSdkAuthBackend } from './firebase_sdk_auth_backend'; @@ -131,19 +132,25 @@ describe('FirebaseAuth', () => { origin:'localhost', href:'https://localhost/' }; - addProviders([ - FIREBASE_PROVIDERS, - defaultFirebase(COMMON_CONFIG), - { provide: FirebaseApp, - useFactory: (config: FirebaseAppConfig) => { - var app = initializeApp(config); - (app).auth = () => authSpy; - return app; + + TestBed.configureTestingModule({ + imports: [AngularFireModule.initializeApp(COMMON_CONFIG, ANON_AUTH_CONFIG)], + providers: [ + { + provide: FirebaseApp, + useFactory: (config: FirebaseAppConfig) => { + var app = initializeApp(config); + (app).auth = () => authSpy; + return app; + }, + deps: [FirebaseConfig] }, - deps: [FirebaseConfig] - }, - { provide: WindowLocation, useValue: windowLocation } - ]); + { + provide: WindowLocation, + useValue: windowLocation + } + ] + }); authSpy = jasmine.createSpyObj('auth', authMethods); authSpy['createUserWithEmailAndPassword'].and.returnValue(Promise.resolve(firebaseUser)); diff --git a/src/auth/auth.ts b/src/auth/auth.ts index 7ec1a96a8..30064f156 100644 --- a/src/auth/auth.ts +++ b/src/auth/auth.ts @@ -1,4 +1,4 @@ -import { Provider, Inject, provide, Injectable, Optional } from '@angular/core'; +import { Provider, Inject, Injectable, Optional } from '@angular/core'; import { Observable } from 'rxjs/Observable'; import { Observer } from 'rxjs/Observer'; import { ReplaySubject } from 'rxjs/ReplaySubject'; diff --git a/src/database/firebase_list_factory.spec.ts b/src/database/firebase_list_factory.spec.ts index d1d8ed10e..946e33b68 100644 --- a/src/database/firebase_list_factory.spec.ts +++ b/src/database/firebase_list_factory.spec.ts @@ -14,25 +14,21 @@ import { FirebaseApp, FirebaseAppConfig, AngularFire, + AngularFireModule } from '../angularfire2'; import { - addProviders, + TestBed, inject } from '@angular/core/testing'; import * as utils from '../utils'; import { Query, AFUnwrappedDataSnapshot } from '../interfaces'; import { Subscription, Observable, Subject } from 'rxjs'; +import { COMMON_CONFIG, ANON_AUTH_CONFIG } from '../test-config'; import 'rxjs/add/operator/do'; import 'rxjs/add/operator/skip'; import 'rxjs/add/operator/take'; -export const firebaseConfig: FirebaseAppConfig = { - apiKey: "AIzaSyBVSy3YpkVGiKXbbxeK0qBnu3-MNZ9UIjA", - authDomain: "angularfire2-test.firebaseapp.com", - databaseURL: "https://angularfire2-test.firebaseio.com", - storageBucket: "angularfire2-test.appspot.com", -}; -const rootFirebase = firebaseConfig.databaseURL; +const rootDatabaseUrl = COMMON_CONFIG.databaseURL; function queryTest(observable: Observable, subject: Subject, done: any) { let nexted = false; @@ -64,7 +60,9 @@ describe('FirebaseListFactory', () => { var app: firebase.app.App; beforeEach(() => { - addProviders([FIREBASE_PROVIDERS, defaultFirebase(firebaseConfig)]); + TestBed.configureTestingModule({ + imports: [AngularFireModule.initializeApp(COMMON_CONFIG, ANON_AUTH_CONFIG)] + }); inject([FirebaseApp, AngularFire], (firebaseApp: firebase.app.App, _af: AngularFire) => { app = firebaseApp; })(); @@ -77,12 +75,12 @@ describe('FirebaseListFactory', () => { describe('constructor', () => { it('should accept a Firebase db url in the constructor', () => { - const list = FirebaseListFactory(`${rootFirebase}/questions`); + const list = FirebaseListFactory(`${rootDatabaseUrl}/questions`); expect(list instanceof FirebaseListObservable).toBe(true); }); it('should accept a Firebase db ref in the constructor', () => { - const list = FirebaseListFactory(firebase.database().refFromURL(`${rootFirebase}/questions`)); + const list = FirebaseListFactory(firebase.database().refFromURL(`${rootDatabaseUrl}/questions`)); expect(list instanceof FirebaseListObservable).toBe(true); }); @@ -102,7 +100,7 @@ describe('FirebaseListFactory', () => { it('equalTo - should re-run a query when the observable value has emitted', (done: any) => { const subject = new Subject(); - const observable = FirebaseListFactory(rootFirebase, { + const observable = FirebaseListFactory(rootDatabaseUrl, { query: { orderByChild: 'height', equalTo: subject @@ -115,7 +113,7 @@ describe('FirebaseListFactory', () => { it('startAt - should re-run a query when the observable value has emitted', (done: any) => { const subject = new Subject(); - const observable = FirebaseListFactory(rootFirebase, { + const observable = FirebaseListFactory(rootDatabaseUrl, { query: { orderByChild: 'height', startAt: subject @@ -128,7 +126,7 @@ describe('FirebaseListFactory', () => { it('endAt - should re-run a query when the observable value has emitted', (done: any) => { const subject = new Subject(); - const observable = FirebaseListFactory(rootFirebase, { + const observable = FirebaseListFactory(rootDatabaseUrl, { query: { orderByChild: 'height', endAt: subject @@ -140,7 +138,7 @@ describe('FirebaseListFactory', () => { it('should throw an error if limitToLast and limitToFirst are chained', () => { - const observable = FirebaseListFactory(rootFirebase, { + const observable = FirebaseListFactory(rootDatabaseUrl, { query: { orderByChild: 'height', limitToFirst: 10, @@ -152,7 +150,7 @@ describe('FirebaseListFactory', () => { it('should throw an error if startAt is used with equalTo', () => { - const observable = FirebaseListFactory(rootFirebase, { + const observable = FirebaseListFactory(rootDatabaseUrl, { query: { orderByChild: 'height', equalTo: 10, @@ -164,7 +162,7 @@ describe('FirebaseListFactory', () => { it('should throw an error if endAt is used with equalTo', () => { - const observable = FirebaseListFactory(rootFirebase, { + const observable = FirebaseListFactory(rootDatabaseUrl, { query: { orderByChild: 'height', equalTo: 10, @@ -176,7 +174,7 @@ describe('FirebaseListFactory', () => { it('should throw an error if startAt and endAt is used with equalTo', () => { - const observable = FirebaseListFactory(rootFirebase, { + const observable = FirebaseListFactory(rootDatabaseUrl, { query: { orderByChild: 'height', equalTo: 10, @@ -201,7 +199,7 @@ describe('FirebaseListFactory', () => { it('equalTo - should re-run a query when the observable value has emitted', (done: any) => { const subject = new Subject(); - const observable = FirebaseListFactory(rootFirebase, { + const observable = FirebaseListFactory(rootDatabaseUrl, { query: { orderByValue: true, equalTo: subject @@ -214,7 +212,7 @@ describe('FirebaseListFactory', () => { it('startAt - should re-run a query when the observable value has emitted', (done: any) => { const subject = new Subject(); - const observable = FirebaseListFactory(rootFirebase, { + const observable = FirebaseListFactory(rootDatabaseUrl, { query: { orderByValue: true, startAt: subject @@ -227,7 +225,7 @@ describe('FirebaseListFactory', () => { it('endAt - should re-run a query when the observable value has emitted', (done: any) => { const subject = new Subject(); - const observable = FirebaseListFactory(rootFirebase, { + const observable = FirebaseListFactory(rootDatabaseUrl, { query: { orderByValue: true, endAt: subject @@ -251,7 +249,7 @@ describe('FirebaseListFactory', () => { it('equalTo - should re-run a query when the observable value has emitted', (done: any) => { const subject = new Subject(); - const observable = FirebaseListFactory(rootFirebase, { + const observable = FirebaseListFactory(rootDatabaseUrl, { query: { orderByKey: true, equalTo: subject @@ -264,7 +262,7 @@ describe('FirebaseListFactory', () => { it('startAt - should re-run a query when the observable value has emitted', (done: any) => { const subject = new Subject(); - const observable = FirebaseListFactory(rootFirebase, { + const observable = FirebaseListFactory(rootDatabaseUrl, { query: { orderByKey: true, startAt: subject @@ -277,7 +275,7 @@ describe('FirebaseListFactory', () => { it('endAt - should re-run a query when the observable value has emitted', (done: any) => { const subject = new Subject(); - const observable = FirebaseListFactory(rootFirebase, { + const observable = FirebaseListFactory(rootDatabaseUrl, { query: { orderByKey: true, endAt: subject @@ -300,7 +298,7 @@ describe('FirebaseListFactory', () => { it('equalTo - should re-run a query when the observable value has emitted', (done: any) => { const subject = new Subject(); - const observable = FirebaseListFactory(rootFirebase, { + const observable = FirebaseListFactory(rootDatabaseUrl, { query: { orderByKey: true, equalTo: subject @@ -313,7 +311,7 @@ describe('FirebaseListFactory', () => { it('startAt - should re-run a query when the observable value has emitted', (done: any) => { const subject = new Subject(); - const observable = FirebaseListFactory(rootFirebase, { + const observable = FirebaseListFactory(rootDatabaseUrl, { query: { orderByKey: true, startAt: subject @@ -326,7 +324,7 @@ describe('FirebaseListFactory', () => { it('endAt - should re-run a query when the observable value has emitted', (done: any) => { const subject = new Subject(); - const observable = FirebaseListFactory(rootFirebase, { + const observable = FirebaseListFactory(rootDatabaseUrl, { query: { orderByKey: true, endAt: subject @@ -342,7 +340,7 @@ describe('FirebaseListFactory', () => { describe('shape', () => { it('should have a a FirebaseListObservable shape when queried', () => { - const observable = FirebaseListFactory(rootFirebase, { + const observable = FirebaseListFactory(rootDatabaseUrl, { query: { orderByChild: 'height', equalTo: '1' @@ -364,14 +362,14 @@ describe('FirebaseListFactory', () => { val2 = { key: 'key2' }; val3 = { key: 'key3' }; firebase.database().ref().remove(done); - questions = FirebaseListFactory(`${rootFirebase}/questions`); - questionsSnapshotted = FirebaseListFactory(`${rootFirebase}/questionssnapshot`, { preserveSnapshot: true }); + questions = FirebaseListFactory(`${rootDatabaseUrl}/questions`); + questionsSnapshotted = FirebaseListFactory(`${rootDatabaseUrl}/questionssnapshot`, { preserveSnapshot: true }); ref = (questions)._ref; refSnapshotted = (questionsSnapshotted)._ref; }); afterEach((done: any) => { - if (subscription && !subscription.isUnsubscribed) { + if (subscription && !subscription.closed) { subscription.unsubscribe(); } Promise.all([ref.remove(), refSnapshotted.remove()]).then(done, done.fail); diff --git a/src/database/firebase_list_observable.spec.ts b/src/database/firebase_list_observable.spec.ts index 26d63d513..b4ca71573 100644 --- a/src/database/firebase_list_observable.spec.ts +++ b/src/database/firebase_list_observable.spec.ts @@ -9,20 +9,16 @@ import { defaultFirebase, FirebaseApp, FirebaseAppConfig, - AngularFire + AngularFire, + AngularFireModule } from '../angularfire2'; import { - addProviders, + TestBed, inject } from '@angular/core/testing'; +import { COMMON_CONFIG, ANON_AUTH_CONFIG } from '../test-config'; -export const firebaseConfig: FirebaseAppConfig = { - apiKey: "AIzaSyBVSy3YpkVGiKXbbxeK0qBnu3-MNZ9UIjA", - authDomain: "angularfire2-test.firebaseapp.com", - databaseURL: "https://angularfire2-test.firebaseio.com", - storageBucket: "angularfire2-test.appspot.com", -}; -const rootUrl = firebaseConfig.databaseURL; +const rootUrl = COMMON_CONFIG.databaseURL; describe('FirebaseObservable', () => { var O:FirebaseListObservable; @@ -30,7 +26,9 @@ describe('FirebaseObservable', () => { var app: firebase.app.App; beforeEach(() => { - addProviders([FIREBASE_PROVIDERS, defaultFirebase(firebaseConfig)]); + TestBed.configureTestingModule({ + imports: [AngularFireModule.initializeApp(COMMON_CONFIG, ANON_AUTH_CONFIG)] + }); inject([FirebaseApp, AngularFire], (firebaseApp: firebase.app.App, _af: AngularFire) => { app = firebaseApp; ref = database().ref(); diff --git a/src/database/firebase_object_factory.spec.ts b/src/database/firebase_object_factory.spec.ts index f0da23140..59521dc24 100644 --- a/src/database/firebase_object_factory.spec.ts +++ b/src/database/firebase_object_factory.spec.ts @@ -1,7 +1,7 @@ import { Subscription } from 'rxjs'; import { FirebaseObjectFactory, FirebaseObjectObservable } from './index'; import { - addProviders, + TestBed, inject } from '@angular/core/testing'; import { @@ -9,16 +9,12 @@ import { defaultFirebase, FirebaseApp, FirebaseAppConfig, - AngularFire + AngularFire, + AngularFireModule } from '../angularfire2'; +import { COMMON_CONFIG, ANON_AUTH_CONFIG } from '../test-config'; -export const firebaseConfig: FirebaseAppConfig = { - apiKey: "AIzaSyBVSy3YpkVGiKXbbxeK0qBnu3-MNZ9UIjA", - authDomain: "angularfire2-test.firebaseapp.com", - databaseURL: "https://angularfire2-test.firebaseio.com", - storageBucket: "angularfire2-test.appspot.com", -}; -const rootFirebase = firebaseConfig.databaseURL; +const rootDatabaseUrl = COMMON_CONFIG.databaseURL; describe('FirebaseObjectFactory', () => { var i = 0; @@ -29,7 +25,9 @@ describe('FirebaseObjectFactory', () => { var app: firebase.app.App; beforeEach(() => { - addProviders([FIREBASE_PROVIDERS, defaultFirebase(firebaseConfig)]); + TestBed.configureTestingModule({ + imports: [AngularFireModule.initializeApp(COMMON_CONFIG, ANON_AUTH_CONFIG)] + }); inject([FirebaseApp, AngularFire], (firebaseApp: firebase.app.App, _af: AngularFire) => { app = firebaseApp; })(); @@ -42,7 +40,7 @@ describe('FirebaseObjectFactory', () => { describe('constructor', () => { it('should accept a Firebase db url in the constructor', () => { - const object = FirebaseObjectFactory(`${rootFirebase}/questions`); + const object = FirebaseObjectFactory(`${rootDatabaseUrl}/questions`); expect(object instanceof FirebaseObjectObservable).toBe(true); }); @@ -59,12 +57,12 @@ describe('FirebaseObjectFactory', () => { i = Date.now(); ref = firebase.database().ref().child(`questions/${i}`); nextSpy = nextSpy = jasmine.createSpy('next'); - observable = FirebaseObjectFactory(`${rootFirebase}/questions/${i}`); + observable = FirebaseObjectFactory(`${rootDatabaseUrl}/questions/${i}`); ref.remove(done); }); afterEach(() => { - if (subscription && !subscription.isUnsubscribed) { + if (subscription && !subscription.closed) { subscription.unsubscribe(); } }); @@ -117,7 +115,7 @@ describe('FirebaseObjectFactory', () => { }); it('should emit snapshots if preserveSnapshot option is true', (done: any) => { - observable = FirebaseObjectFactory(`${rootFirebase}/questions/${i}`, { preserveSnapshot: true }); + observable = FirebaseObjectFactory(`${rootDatabaseUrl}/questions/${i}`, { preserveSnapshot: true }); ref.remove(() => { ref.set('preserved snapshot!', () => { subscription = observable.subscribe(data => { diff --git a/src/database/firebase_object_observable.spec.ts b/src/database/firebase_object_observable.spec.ts index 222f9c7d4..d3ef9d71b 100644 --- a/src/database/firebase_object_observable.spec.ts +++ b/src/database/firebase_object_observable.spec.ts @@ -1,5 +1,5 @@ import { - addProviders, + TestBed, inject } from '@angular/core/testing'; import { @@ -7,20 +7,16 @@ import { defaultFirebase, FirebaseApp, FirebaseAppConfig, - AngularFire + AngularFire, + AngularFireModule } from '../angularfire2'; +import { COMMON_CONFIG, ANON_AUTH_CONFIG } from '../test-config'; import { FirebaseObjectObservable } from './index'; import { Observer } from 'rxjs/Observer'; import 'rxjs/add/operator/map'; import { database } from 'firebase'; -export const firebaseConfig: FirebaseAppConfig = { - apiKey: "AIzaSyBVSy3YpkVGiKXbbxeK0qBnu3-MNZ9UIjA", - authDomain: "angularfire2-test.firebaseapp.com", - databaseURL: "https://angularfire2-test.firebaseio.com", - storageBucket: "angularfire2-test.appspot.com", -}; -const rootUrl = firebaseConfig.databaseURL; +const rootDatabaseUrl = COMMON_CONFIG.databaseURL; describe('FirebaseObjectObservable', () => { @@ -29,7 +25,9 @@ describe('FirebaseObjectObservable', () => { var app: firebase.app.App; beforeEach(() => { - addProviders([FIREBASE_PROVIDERS, defaultFirebase(firebaseConfig)]); + TestBed.configureTestingModule({ + imports: [AngularFireModule.initializeApp(COMMON_CONFIG, ANON_AUTH_CONFIG)] + }); inject([FirebaseApp, AngularFire], (firebaseApp: firebase.app.App, _af: AngularFire) => { app = firebaseApp; ref = database().ref() diff --git a/src/database/query_observable.ts b/src/database/query_observable.ts index 6f3261099..ea3d25e98 100644 --- a/src/database/query_observable.ts +++ b/src/database/query_observable.ts @@ -22,17 +22,18 @@ export function observeQuery(query: Query): Observable { } return Observable.create((observer: Observer) => { - getOrderObservables(query) - .combineLatest( - getStartAtObservable(query), - getEndAtObservable(query), - getEqualToObservable(query), - getLimitToObservables(query) + + let obs = getOrderObservables(query) as Observable; + obs.combineLatest( + getStartAtObservable(query), + getEndAtObservable(query), + getEqualToObservable(query), + getLimitToObservables(query) ) .subscribe(([orderBy, startAt, endAt, equalTo, limitTo] : [OrderBySelection, Primitive, Primitive, Primitive, LimitToSelection]) => { - var serializedOrder: any = {}; + let serializedOrder: any = {}; if (isPresent(orderBy) && isPresent(orderBy.value)) { switch (orderBy.key) { case OrderByOptions.Key: diff --git a/src/test-config.ts b/src/test-config.ts index b2d9b8fb0..80d008eb7 100644 --- a/src/test-config.ts +++ b/src/test-config.ts @@ -1,6 +1,13 @@ +import { AuthMethods, AuthProviders } from './auth/index'; + export const COMMON_CONFIG = { apiKey: "AIzaSyBVSy3YpkVGiKXbbxeK0qBnu3-MNZ9UIjA", authDomain: "angularfire2-test.firebaseapp.com", databaseURL: "https://angularfire2-test.firebaseio.com", storageBucket: "angularfire2-test.appspot.com", }; + +export const ANON_AUTH_CONFIG = { + method: AuthMethods.Anonymous, + provider: AuthProviders.Anonymous +}; diff --git a/src/utils.ts b/src/utils.ts index c202dcb2d..cdbaf1099 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,5 +1,6 @@ import { Subscription } from 'rxjs/Subscription'; import { QueueScheduler } from 'rxjs/scheduler/QueueScheduler'; +import { QueueAction } from 'rxjs/scheduler/QueueAction'; import { Scheduler } from 'rxjs/Scheduler'; import { AFUnwrappedDataSnapshot} from './interfaces'; @@ -96,7 +97,7 @@ export function stripLeadingSlash(value: string): string { */ export class ZoneScheduler extends QueueScheduler { constructor(public zone: Zone) { - super(); + super(QueueAction); } schedule(...args): Subscription { diff --git a/tsconfig.json b/tsconfig.json index e2fd37f8b..1bed18251 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -14,7 +14,8 @@ "lib": [ "es2015", "dom" - ] + ], + "skipLibCheck": true }, "files": [ "src/angularfire2.ts",