fireproof
Version:
Promises for Firebase objects.
95 lines (58 loc) • 1.99 kB
JavaScript
describe('Fireproof', function() {
var fireproof;
beforeEach(function() {
fireproof = new Fireproof(firebase);
});
describe('#then', function() {
before(function() {
fireproof = new Fireproof(firebase);
return fireproof.child('thentest').set(true);
});
it('hands back a snapshot of the ref by default', function(done) {
fireproof.child('thentest').then(function(snap) {
expect(snap.val()).to.equal(true);
done();
}, done);
});
});
describe('bless', function() {
it('handles deferrable promise libraries okay', function(done) {
Fireproof.bless(require('kew'));
fireproof.child('thentest').then(function(snap) {
expect(snap.val()).to.equal(true);
done();
}, done);
});
});
describe('#child', function() {
it('returns a Fireproof to the named child of the parent', function() {
expect(fireproof.child('foo')).to.be.an.instanceof(Fireproof);
expect(fireproof.child('foo').toString()).to.match(/foo$/);
});
});
describe('#parent', function() {
it('returns null for a top-level reference', function() {
expect(fireproof.parent()).to.equal(null);
});
it('returns a Fireproof to the parent of the ref', function() {
expect(fireproof.child('foo').parent().toString())
.to.equal(fireproof.toString());
});
});
describe('#root', function() {
it('returns a reference to the root of the associated Firebase', function() {
expect(fireproof.child('foo').child('bar').root().toString())
.to.equal(fireproof.toString());
});
});
describe('#key', function() {
it('returns null for a top-level reference', function() {
expect(fireproof.key()).to.equal(null);
});
it('returns the last part of the name of a reference', function() {
expect(fireproof.child('foo').child('bar').key())
.to.equal('bar');
});
});
});
;