Closed mattvv closed 10 years ago
Huh. That's really weird. Mind posting your full test file?
Thanks for the super fast response @bendrucker I'm using node.js + mocha + should.
spec/spec.js
var should = require('should');
var proxyquire = require('proxyquire');
var server = proxyquire('./src/server', {
firebase: require('mockfirebase').MockFirebase.autoFlush()
});
describe('Server', function() {
it ('should pass a test', function() {
true.should.be.true;
})
});
src/server.js
var Firebase = require('firebase');
var firebaseUrl = process.env.FIREBASE_URL || 'https://redacted.firebaseio.com/';
var api_key = process.env.FIREBASE_API_KEY || 'redacted';
var companiesRef = new Firebase(firebaseUrl);
var companies;
function listenForChanges() {
companiesRef.auth(api_key, function(error) {
if (error) {
console.log('Login Failed!!', error);
} else {
companiesRef.on('value', function(snapshot) {
companies = snapshot.val();
});
}
});
}
listenForChanges();
exports.firebaseUrl = firebaseUrl;
exports.app = app;
exports.listenForChanges = listenForChanges;
Realizing now that I screwed things up a little in Node with the way the build process stands right now. Hadn't noticed it because I have my Node apps pinned to an old version. Will pop this in a branch now. If you can confirm it works I'll cut it as 0.3.0.
d6f2e97bd7a524494a2039915977649057b48be0 should fix this. Give it a shot by replacing "~0.2.9" in your package.json with git://github.com/katowulf/mockfirebase.git#d6f2e97bd7a524494a2039915977649057b48be0. Will release it to npm as 0.3.0 if it looks good.
Thanks for the super quick turnaround. Still having issues with that same example. In this case:
/Users/mattvv/Documents/curiousminds/whistle-sms/spec/serverSpec.js:9
uire('../src/server',{firebase:require('mockfirebase').MockFirebase.autoFlush(
^
TypeError: Object function MockFirebase(currentPath, data, parent, name) {
// represents the fake url
//todo should unwrap nested paths; Firebase
//todo accepts sub-paths, mock should too
this.currentPath = currentPath || 'Mock://';
// see failNext()
this.errs = {};
// used for setPriorty and moving records
this.priority = null;
// null for the root path
this.myName = parent? name : extractName(currentPath);
// see autoFlush() and flush()
this.flushDelay = parent? parent.flushDelay : false;
this.flushQueue = parent? parent.flushQueue : new FlushQueue();
// stores the listeners for various event types
this._events = { value: [], child_added: [], child_removed: [], child_changed: [], child_moved: [] };
// allows changes to be propagated between child/parent instances
this.parentRef = parent||null;
this.children = {};
if (parent) parent.children[this.name()] = this;
// stores sorted keys in data for priority ordering
this.sortedDataKeys = [];
// do not modify this directly, use set() and flush(true)
this.data = null;
this._dataChanged(_.cloneDeep(arguments.length > 1? data||null : MockFirebase.DEFAULT_DATA));
// stores the last auto id generated by push() for tests
this._lastAutoId = null;
// turn all our public methods into spies so they can be monitored for calls and return values
// see jasmine spies: https://github.com/pivotal/jasmine/wiki/Spies
// the Firebase constructor can be spied on using spyOn(window, 'Firebase') from within the test unit
for(var key in this) {
if( !key.match(/^_/) && typeof(this[key]) === 'function' ) {
spyFactory(this, key);
}
}
} has no method 'autoFlush'
at Object.<anonymous> (/Users/mattvv/Documents/curiousminds/whistle-sms/spec/serverSpec.js:9:266)
New errors! Progress-ish. Hang on.
So that was a documentation mistake. autoFlush
is on the prototype. That example was either wrong to begin with or outdated. Try the updated instructions:
Seems to be at least running the tests now! I'll investigate further early next week when I am back in town :) Thanks for your quick responses!
Awesome!
Hey @katowulf - Loving that you guys are making a mock library for this.
I know this is beta/unstable but i'd thought i'd post anyway.
I'm having trouble following the example you guys listed using proxyquire. When I follow it and run my tests I get: