mirror of
https://github.com/zhigang1992/react-native-firebase.git
synced 2026-04-27 19:25:20 +08:00
-
This commit is contained in:
@@ -15,16 +15,17 @@
|
||||
*
|
||||
*/
|
||||
|
||||
const { PATH, seed, wipe } = require('../helpers');
|
||||
const { PATH } = require('../helpers');
|
||||
|
||||
const TEST_PATH = `${PATH}/push`;
|
||||
|
||||
describe.only('database().ref().push()', () => {
|
||||
// before(() => seed(TEST_PATH));
|
||||
// after(() => wipe(TEST_PATH));
|
||||
// TODO
|
||||
describe('database().ref().push()', () => {
|
||||
|
||||
it('wraps Firebase.push when no value is passed', () => {
|
||||
// onComplete function check
|
||||
// onComplete success / error check
|
||||
// unhandled rejection with onComplete
|
||||
|
||||
it('returns a promise when no value is passed', () => {
|
||||
const ref = firebase.database().ref(`${TEST_PATH}/boop`);
|
||||
const pushed = ref.push();
|
||||
return pushed
|
||||
@@ -38,4 +39,19 @@ describe.only('database().ref().push()', () => {
|
||||
snap.ref.toString().should.eql(pushed.toString());
|
||||
});
|
||||
});
|
||||
|
||||
it('returns a promise and sets the provided value', () => {
|
||||
const ref = firebase.database().ref(`${TEST_PATH}/value`);
|
||||
const pushed = ref.push(6);
|
||||
return pushed
|
||||
.then(childRef => {
|
||||
pushed.ref.parent.toString().should.eql(ref.toString());
|
||||
pushed.toString().should.eql(childRef.toString());
|
||||
return pushed.once('value');
|
||||
})
|
||||
.then(snap => {
|
||||
snap.val().should.equal(6);
|
||||
snap.ref.toString().should.eql(pushed.toString());
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -17,11 +17,13 @@
|
||||
|
||||
const { PATH } = require('../helpers');
|
||||
|
||||
const TEST_PATH = `${PATH}/update`;
|
||||
|
||||
describe('database().ref().update()', () => {
|
||||
after(async () => {
|
||||
await firebase
|
||||
.database()
|
||||
.ref(`${PATH}/update`)
|
||||
.ref(TEST_PATH)
|
||||
.remove();
|
||||
});
|
||||
|
||||
@@ -29,7 +31,7 @@ describe('database().ref().update()', () => {
|
||||
try {
|
||||
await firebase
|
||||
.database()
|
||||
.ref(`${PATH}/update`)
|
||||
.ref(TEST_PATH)
|
||||
.update('foo');
|
||||
return Promise.reject(new Error('Did not throw an Error.'));
|
||||
} catch (error) {
|
||||
@@ -42,7 +44,7 @@ describe('database().ref().update()', () => {
|
||||
try {
|
||||
await firebase
|
||||
.database()
|
||||
.ref(`${PATH}/update`)
|
||||
.ref(TEST_PATH)
|
||||
.update({});
|
||||
return Promise.reject(new Error('Did not throw an Error.'));
|
||||
} catch (error) {
|
||||
@@ -70,7 +72,7 @@ describe('database().ref().update()', () => {
|
||||
try {
|
||||
await firebase
|
||||
.database()
|
||||
.ref(`${PATH}/update`)
|
||||
.ref(TEST_PATH)
|
||||
.update(
|
||||
{
|
||||
foo: 'bar',
|
||||
@@ -86,7 +88,7 @@ describe('database().ref().update()', () => {
|
||||
|
||||
it('updates values', async () => {
|
||||
const value = Date.now();
|
||||
const ref = firebase.database().ref(`${PATH}/update`);
|
||||
const ref = firebase.database().ref(TEST_PATH);
|
||||
await ref.update({
|
||||
foo: value,
|
||||
});
|
||||
@@ -103,7 +105,7 @@ describe('database().ref().update()', () => {
|
||||
return new Promise(async resolve => {
|
||||
await firebase
|
||||
.database()
|
||||
.ref(`${PATH}/update`)
|
||||
.ref(TEST_PATH)
|
||||
.update(
|
||||
{
|
||||
foo: value,
|
||||
|
||||
Reference in New Issue
Block a user