Skip to content

Latest commit

 

History

History
30 lines (25 loc) · 856 Bytes

proxyquire.md

File metadata and controls

30 lines (25 loc) · 856 Bytes

Tutorial: Overriding require('firebase')

In Node/Browserify, you need to patch require itself to override Firebase calls. The trio of proxyquire (Node), proxyquireify (Browserify), and proxyquire-universal (both) make this easy.

Source
// ./mySrc.js
var Firebase = require('firebase');
var ref = new Firebase('myRefUrl');
ref.on('value', function (snapshot) {
  console.log(snapshot.val());
});
Test
// ./test.js
var proxyquire   = require('proxyquire');
var MockFirebase = require('mockfirebase').MockFirebase;
var mock;
var mySrc = proxyquire('./mySrc', {
  firebase: function (url) {
    return (mock = new MockFirebase(url));
  }
});
mock.flush();
// data is logged