本文介绍了名为“[DEFAULT]"的 Firebase 应用已存在(应用/重复应用)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 AngularJS + Firebase 开发一个简单的 Web 时进行单元测试,但是我在定义规范和尝试测试运行程序时遇到了问题

Hi I am trying to unit test while developing a simple web with AngularJS + Firebase, but I have a problem defining the spec and trying the test runner

myProject/test/spec/main.js :

myProject/test/spec/main.js :

describe('Controller: MainCtrl', function() {

var MainCtrl, scope

beforeEach(module('MainApp'));

beforeEach(inject(function ($controller, $rootScope) {
    scope = $rootScope.$new();
    MainCtrl = $controller('MainCtrl', {
        $scope: scope
    })
}));

it('should....',function(){
    expect(true).toBe(true)
})
it('should2....',function(){
    expect(false).toBe(false)
})
});

结果:

PhantomJS 2.1.1 (Mac OS X 0.0.0) Controller: MainCtrl should.... FAILED
Error: [$injector:modulerr] Failed to instantiate module MainApp due
to: Firebase: Firebase App named '[DEFAULT]' already exists
(app/duplicateapp).

然而,定义一次规范不是问题.例如:

However, defining the spec once is not a problem. For example:

it('should....',function(){
   expect(true).toBe(true)
})

我不知道为什么这是我给我提示的原因

I do not know why this is the reason I give a hint to me

这是我正在开发的项目.

Here is the project I am developing.

https://github.com/parkwookyun/firebase-angular-board

推荐答案

if (!firebase.apps.length) {
   firebase.initializeApp({});
}else {
   firebase.app(); // if already initialized, use that one
}

这里有类似的答案

这篇关于名为“[DEFAULT]"的 Firebase 应用已存在(应用/重复应用)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 18:01