angularfire icon indicating copy to clipboard operation
angularfire copied to clipboard

Angular 6 NG test with Angularfirestore.

Open ghost opened this issue 8 years ago • 4 comments

Hey guys.

My code works fine with angularfire2 firestore.

But my spec file fails in test.

As soon as i add constructor(private afs: AngularFirestore) { }

in my components constructor my tests fail NullInjectorError: No provider for AngularFirestore

But even when i add AngularFirestore my spec file testBed like this

import { AngularFirestoreModule } from 'angularfire2/firestore';

 TestBed.configureTestingModule({
      declarations: [MyComponent],
      providers: [AngularFirestoreModule]```

I still get the same error.

This is my app.module

import { AngularFireModule } from 'angularfire2';
import { AngularFirestoreModule } from 'angularfire2/firestore';

import { environment } from '../environments/environment';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [

    // firebase  modules  
    AngularFireModule.initializeApp(environment.firebase),
    AngularFirestoreModule
  ],
  providers: [],
})
export class AppModule { }

PLease help.

Here is a link to my repository

https://github.com/acc2link/Angular6

ghost avatar Jun 03 '18 11:06 ghost

One thing that looks odd to me is your app.module has AngularFirestoreModule under imports, but your test file has it under providers. Is it supposed to be consistent? Also, if you put it under providers is it supposed to be AngularFirestore instead of AngularFirestoreModule?

jsparks19 avatar Jun 03 '18 20:06 jsparks19

When i put AngularFirestore as provider in my test I get No provider for InjectionToken angularfire2.app.options!

Thanks @jsparks19 .. My version of angular is 6.

ghost avatar Jun 04 '18 00:06 ghost

Created a new issue https://github.com/angular/angularfire2/issues/1706

ghost avatar Jun 04 '18 00:06 ghost

https://github.com/angular/angularfire2/issues/1706#issuecomment-394212606

ksaifullah avatar Jun 04 '18 01:06 ksaifullah