Angularfire: Angular unit test error: Failed: Invalid provider for the NgModule 'DynamicTestModule' - only instances of Provider and Type are allowed, got: [AngularFireDatabase, ?[object Object]?, ...]

Created on 13 Oct 2017  路  6Comments  路  Source: angular/angularfire

Version info

Angular:

  
   "@angular/animations": "^4.2.4",
    "@angular/common": "^4.2.4",
    "@angular/compiler": "^4.2.4",
    "@angular/core": "^4.2.4",
    "@angular/forms": "^4.2.4",
    "@angular/http": "^4.2.4",
    "@angular/platform-browser": "^4.2.4",
    "@angular/platform-browser-dynamic": "^4.2.4",
    "@angular/router": "^4.2.4",
    "angularfire2": "^5.0.0-rc.2",
    "core-js": "^2.4.1",
    "firebase": "^4.5.1",
    "rxjs": "^5.4.2",
    "zone.js": "^0.8.14"
 

Firebase:
"firebase": "^4.5.1",

AngularFire:
"angularfire2": "^5.0.0-rc.2",

Other (e.g. Ionic/Cordova, Node, browser, operating system):

How to reproduce these conditions

Failing test unit, Plunkr, or JSFiddle demonstrating the problem

Steps to set up and reproduce

Sample data and security rules

<-- include/attach/link to some json sample data (or provide credentials to a sanitized, test Firebase project) -->

Debug output

image

Spec.ts Code


import { AngularFireDatabase } from "angularfire2/database";
import { AngularFireModule } from "angularfire2";
import { TestBed, async } from "@angular/core/testing";
import { AppComponent } from "./app.component";
import { FirebaseApp } from "angularfire2";
describe("AppComponent", () => {
    beforeEach(async(() => {
        TestBed.configureTestingModule({
            declarations: [
                AppComponent
            ],
            providers: [
                AngularFireDatabase,
                AngularFireModule.initializeApp({
                    apiKey: "",
                    authDomain: "",
                    databaseURL: "",
                    projectId: "",
                    storageBucket: "",
                    messagingSenderId: ""
                }),
                FirebaseApp,
            ]
        }).compileComponents();
    }));
});

What should I do?
I just import angularfire after ng new.
and I want unit test.

Most helpful comment

I had the same bug, but I had a problem and for what I wrote "provider" but you had to write "provide"

All 6 comments

@YoonJaePark Can you take a look at how we setup our unit tests? We do something similar and don't have any problems. This is likely a config issue but I can't tell where the problem lies.

https://github.com/angular/angularfire2/blob/master/src/core/angularfire2.spec.ts

Closing due to inactivity. Please feel free to open another if the problem is persisting.

Have you solved the problem?I have the same problem

I had the same bug, but I had a problem and for what I wrote "provider" but you had to write "provide"

Just adding that in an Ionic v4 project, this may be caused by using Ionic Native plugins without appending /ngx to the corresponding import. E.g.

// wrong
import {WebView} from '@ionic-native/ionic-webview';
// correct
import {WebView} from '@ionic-native/ionic-webview/ngx';

Just encountered same error and tracked it down to wrongly placing RouterTestingModule.withRoutes([...someRoutes]) into providers instead of into imports.

Was this page helpful?
0 / 5 - 0 ratings