mirror of
https://github.com/zhigang1992/react-native-firebase.git
synced 2026-05-21 07:32:47 +08:00
- [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.
35 lines
1.1 KiB
JavaScript
35 lines
1.1 KiB
JavaScript
const { setDatabaseContents } = TestHelpers.database;
|
|
|
|
// TODO use testRunId in refs to prevent multiple test instances interfering with each other
|
|
describe('database()', () => {
|
|
before(() => setDatabaseContents());
|
|
describe('ref.transaction()', () => {
|
|
it('increments a value', async () => {
|
|
let valueBefore = 1;
|
|
const ref = firebase.database().ref('tests/transaction');
|
|
|
|
const { committed, snapshot } = await ref.transaction(currentData => {
|
|
if (currentData === null) {
|
|
return valueBefore + 10;
|
|
}
|
|
valueBefore = currentData;
|
|
return valueBefore + 10;
|
|
}, true);
|
|
|
|
should.equal(committed, true, 'Transaction did not commit.');
|
|
snapshot.val().should.equal(valueBefore + 10);
|
|
});
|
|
|
|
it('aborts if undefined returned', async () => {
|
|
const ref = firebase.database().ref('tests/transaction');
|
|
|
|
const { committed } = await ref.transaction(() => undefined, true);
|
|
should.equal(
|
|
committed,
|
|
false,
|
|
'Transaction committed and did not abort.'
|
|
);
|
|
});
|
|
});
|
|
});
|