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

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.'
);
});
});
});