Firebase App named '[DEFAULT]' already exists (app/duplicate-app) [duplicate] Ask Question

Firebase App named '[DEFAULT]' already exists (app/duplicate-app) [duplicate] Ask Question

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 :

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)
})
});

result:

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).

ただし、仕様を一度定義すれば問題ありません。例:

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

なぜこれが私にヒントを与える理由なのか分かりません

私が開発しているプロジェクトはこちらです。

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

ベストアンサー1

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

同様の回答はこちら

おすすめ記事