2
//index.js
const functions = require('firebase-functions');
var Queue = require('firebase-queue');

var specQueue = new Queue();

//test.js
var assert = require('assert');
var sinon = require('sinon');
describe('test', function() {
  var Queue, firebaseQueueStub;

  before(() => {
    Queue =  require('firebase-queue');
    firebaseQueueStub = sinon.createStubInstance(Queue);
    myFunctions = require('../index');
  });

  describe('CREATED', function() {
      it('should return -1 when the value is not present', function() {
            assert.equal(-1, [1,5,3].indexOf(4));
          });
    });
});

How does one stub the firebase queue constructor in index.js? I've tried the above but firebase-queue is still being called instead of my stub. Thanks.

user3240644
  • 2,211
  • 2
  • 24
  • 35
  • 1
    `firebase-queue` is not compatible with Cloud Functions for Firebase -- it predated functions and most of the things done by firebase-queue can be better done directly in Cloud Functions. – Michael Bleigh Dec 06 '17 at 03:24
  • Agree with Michael. You can implement your own queue by pushing into a location at the database to trigger the function. I had a talk on this at I/O. https://www.youtube.com/watch?v=eWj6dxfN63g – Doug Stevenson Dec 06 '17 at 04:44
  • Thanks for the info. However, how does one stub it anyhow? i've got some legacy code that I'm writing tests for so i'd need to stub it out for now. – user3240644 Dec 06 '17 at 07:34

0 Answers0