Karma单元测试中名为“ [DEFAULT]”的Firebase应用已存在app / duplicate-app错误

问题描述

我正在尝试为Angular / Firebase应用程序创建单元测试,但出现以下错误:

Uncaught Error in snapshot listener: FirebaseError: Missing or insufficient permissions.

FirebaseError: Firebase: Firebase App named '[DEFAULT]' already exists (app/duplicate-app).

以下是几个说明的示例:

import { async,ComponentFixture,TestBed } from '@angular/core/testing';
import { IonicModule } from '@ionic/angular';

import { ChatPage } from './chat.page';
import * as firebase from 'firebase/app';
import { firebaseConfig } from 'src/credentials/credentials';
firebase.initializeApp(firebaseConfig);

describe('ChatPage',() => {
  let component: ChatPage;
  let fixture: ComponentFixture<ChatPage>;

  beforeEach(async(() => {
    TestBed.configureTestingModule({
      declarations: [ ChatPage ],imports: [IonicModule.forRoot()]
    }).compileComponents();

    fixture = TestBed.createComponent(ChatPage);
    component = fixture.componentInstance;
    fixture.detectChanges();
  }));

  it('should create',() => {
    expect(component).toBeTruthy();
  });
});

这是我未添加firebaseInit的地方:

import { async,TestBed } from '@angular/core/testing';
import { IonicModule } from '@ionic/angular';
import { FormsModule,ReactiveFormsModule } from '@angular/forms';
import { RouterTestingModule } from '@angular/router/testing';

import { SignupPage } from './signup.page';

describe('SignupPage',() => {
  let component: SignupPage;
  let fixture: ComponentFixture<SignupPage>;

  beforeEach(async(() => {
    TestBed.configureTestingModule({
      declarations: [ SignupPage ],imports: [IonicModule.forRoot(),FormsModule,ReactiveFormsModule,RouterTestingModule]
    }).compileComponents();

    fixture = TestBed.createComponent(SignupPage);
    component = fixture.componentInstance;
    fixture.detectChanges();
  }));

  it('should create',() => {
    expect(component).toBeTruthy();
  });
});

在使用业力对FirebaseAngular应用进行单元测试时,我找不到任何示例或教程,所以我开枪了。

任何帮助将不胜感激。进行Firebase应用程序单元测试的设置步骤是什么?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...