1
をテストする際にストレージがスタブすることはできません私はindex.js内部に以下の機能コードを持っている:Firebase機能:書き込みユニットは
var admin = require('firebase-admin');
admin.initializeApp();
admin.storage();
そして、次のテストコード:
var assert = require('assert');
var sinon = require('sinon');
describe('Event Sourcing', function() {
var myFunctions, adminInitStub, adminStorageStub,admin;
before(() => {
admin = require('firebase-admin');
adminStorageStub = sinon.stub(admin, 'storage');
adminInitStub = sinon.stub(admin, 'initializeApp');
myFunctions = require('../index');
});
after(() => {
// Restoring our stubs to the original methods.
adminInitStub.restore();
adminStorageStub.restore();
});
describe('CREATED', function() {
it('should return -1 when the value is not present', function() {
assert.equal(-1, [1,5,3].indexOf(4));
});
});
});
いくつかの奇妙な理由で、私は次のエラーError: The default Firebase app does not exist. Make sure you call initializeApp() before using any of the Firebase services.
を得続けますが、私はそれを明確に突き詰めました。スタブはinitializeApp()では動作しますが、storage()では動作しません。
ありがとうございます!