Files
react-native-firebase/tests/e2e/database/rnReload.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

98 lines
2.9 KiB
JavaScript

const { CONTENTS, setDatabaseContents } = TestHelpers.database;
describe('database()', () => {
before(() => setDatabaseContents());
describe('ref().once()', () => {
it('same reference path works after React Native reload', async () => {
let ref;
let snapshot;
const path = 'tests/types/number';
const dataTypeValue = CONTENTS.DEFAULT.number;
// before reload
ref = firebase.database().ref(path);
snapshot = await ref.once('value');
snapshot.val().should.eql(dataTypeValue);
// RELOAD
await device.reloadReactNative();
// after reload
ref = firebase.database().ref(path);
snapshot = await ref.once('value');
snapshot.val().should.eql(dataTypeValue);
}).timeout(15000);
it(':android: same reference path works after app backgrounded', async () => {
let ref;
let snapshot;
const path = 'tests/types/number';
const dataTypeValue = CONTENTS.DEFAULT.number;
// before
ref = firebase.database().ref(path);
snapshot = await ref.once('value');
snapshot.val().should.eql(dataTypeValue);
await device.sendToHome();
await sleep(250);
await device.launchApp({ newInstance: false });
await sleep(250);
// after
ref = firebase.database().ref(path);
snapshot = await ref.once('value');
snapshot.val().should.eql(dataTypeValue);
}).timeout(15000);
});
describe('ref().on()', () => {
it('same reference path works after React Native reload', async () => {
let ref;
let snapshot;
const path = 'tests/types/number';
const dataTypeValue = CONTENTS.DEFAULT.number;
// before reload
ref = firebase.database().ref(path);
snapshot = await new Promise(resolve => ref.on('value', resolve));
snapshot.val().should.eql(dataTypeValue);
// RELOAD
await device.reloadReactNative();
// after reload
ref = firebase.database().ref(path);
snapshot = await new Promise(resolve => ref.on('value', resolve));
snapshot.val().should.eql(dataTypeValue);
firebase.utils().database.cleanup();
}).timeout(15000);
it(':android: same reference path works after app backgrounded', async () => {
let ref;
let snapshot;
const path = 'tests/types/number';
const dataTypeValue = CONTENTS.DEFAULT.number;
// before background
ref = firebase.database().ref(path);
snapshot = await new Promise(resolve => ref.on('value', resolve));
snapshot.val().should.eql(dataTypeValue);
await device.sendToHome();
await sleep(250);
await device.launchApp({ newInstance: false });
await sleep(250);
// after background
ref = firebase.database().ref(path);
snapshot = await new Promise(resolve => ref.on('value', resolve));
snapshot.val().should.eql(dataTypeValue);
firebase.utils().database.cleanup();
}).timeout(15000);
});
});