Files
react-native-firebase/tests/e2e/database/snapshot.e2e.js
Michael Diarmid d3b9b24cca [android][database] database improvements (#1619)
- [ANDROID] [BUGFIX] [DATABASE] - Database listeners now correctly tearing down between RN reloads. (Fixes #1498 #1611 #1609)
 - [JS] [BUGFIX] [DATABASE] - Fixed an issue where `Reference.toString()` incorrectly contains `//` instead of `/` when joining the parent and child paths.
 - [JS] [BUGFIX] [DATABASE] - Rework `.push()` behaviour to match WebSDK and correctly return a Reference instance in all scenarios. (Fixes #893 #1464 #1572)
 - [JS] [ENHANCEMENT] [UTILS] - Added a `firebase.utils().database.cleanup()` utility method which removes all database listeners.
2018-10-27 05:34:09 +01:00

104 lines
3.0 KiB
JavaScript

const { setDatabaseContents } = TestHelpers.database;
describe('database()', () => {
describe('Snapshot', () => {
before(() => setDatabaseContents());
it('should provide a functioning val() method', async () => {
const snapshot = await firebase
.database()
.ref('tests/types/array')
.once('value');
snapshot.val.should.be.a.Function();
snapshot.val().should.eql(jet.Array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]));
});
it('should provide a functioning child() method', async () => {
const snapshot = await firebase
.database()
.ref('tests/types/array')
.once('value');
snapshot.child('0').val.should.be.a.Function();
snapshot
.child('0')
.val()
.should.equal(0);
snapshot.child('0').key.should.be.a.String();
snapshot.child('0').key.should.equal('0');
});
// TODO refactor
it('should provide a functioning hasChild() method', async () => {
const snapshot = await firebase
.database()
.ref('tests/types/object')
.once('value');
snapshot.hasChild.should.be.a.Function();
snapshot.hasChild('foo').should.equal(true);
snapshot.hasChild('baz').should.equal(false);
});
it('should provide a functioning hasChildren() method', async () => {
const snapshot = await firebase
.database()
.ref('tests/types/object')
.once('value');
snapshot.hasChildren.should.be.a.Function();
snapshot.hasChildren().should.equal(true);
snapshot
.child('foo')
.hasChildren()
.should.equal(false);
});
it('should provide a functioning exists() method', async () => {
const snapshot = await firebase
.database()
.ref('tests/types/object/baz/daz')
.once('value');
snapshot.exists.should.be.a.Function();
snapshot.exists().should.equal(false);
});
it('should provide a functioning getPriority() method', async () => {
const ref = firebase.database().ref('tests/priority');
const snapshot = await ref.once('value');
snapshot.getPriority.should.be.a.Function();
snapshot.getPriority().should.equal(666);
snapshot.val().should.eql(jet.Object({ foo: 'bar' }));
});
it('should provide a functioning forEach() method', async () => {
const snapshot = await firebase
.database()
.ref('tests/types/array')
.once('value');
let total = 0;
snapshot.forEach.should.be.a.Function();
snapshot.forEach(childSnapshot => {
const val = childSnapshot.val();
total += val;
return val === 3; // stop iteration after key 3
});
total.should.equal(6); // 0 + 1 + 2 + 3 = 6
});
it('should provide a key property', async () => {
const snapshot = await firebase
.database()
.ref('tests/types/array')
.once('value');
snapshot.key.should.be.a.String();
snapshot.key.should.equal('array');
});
});
});