From 9cd4641f06f78f3ddc1bf92581d7b967f87cf21f Mon Sep 17 00:00:00 2001 From: Salakar Date: Tue, 4 Jul 2017 16:19:41 +0100 Subject: [PATCH] [tests][database] added 'child_added' test for issue #221 - thanks @TiraO --- tests/ios/Podfile.lock | 4 +-- tests/src/tests/database/ref/index.js | 3 +- .../database/ref/on/onChildAddedTests.js | 36 +++++++++++++++++++ tests/src/tests/database/ref/refTests.js | 4 +-- 4 files changed, 41 insertions(+), 6 deletions(-) create mode 100644 tests/src/tests/database/ref/on/onChildAddedTests.js diff --git a/tests/ios/Podfile.lock b/tests/ios/Podfile.lock index bf2bd152..d72cb893 100644 --- a/tests/ios/Podfile.lock +++ b/tests/ios/Podfile.lock @@ -98,7 +98,7 @@ PODS: - React/cxxreact (0.44.3): - React/jschelpers - React/jschelpers (0.44.3) - - RNFirebase (1.1.2) + - RNFirebase (2.0.0) - Yoga (0.44.3.React) DEPENDENCIES: @@ -143,7 +143,7 @@ SPEC CHECKSUMS: GTMSessionFetcher: 30d874b96d0d76028f61fbd122801e3f030d47db Protobuf: d582fecf68201eac3d79ed61369ef45734394b9c React: 6361345ebeb769a929e10a06baf0c868d6d03ad5 - RNFirebase: 7310b8755cc32583f62f11e61b28f839046de5eb + RNFirebase: dcc4dcb1c9400a9bc01866e50d1351272a7df311 Yoga: c90474ca3ec1edba44c97b6c381f03e222a9e287 PODFILE CHECKSUM: 45666f734ebfc8b3b0f2be0a83bc2680caeb502f diff --git a/tests/src/tests/database/ref/index.js b/tests/src/tests/database/ref/index.js index 124155db..8cc11c01 100644 --- a/tests/src/tests/database/ref/index.js +++ b/tests/src/tests/database/ref/index.js @@ -1,5 +1,6 @@ import onTests from './on/onTests'; import onValueTests from './on/onValueTests'; +import onChildAddedTests from './on/onChildAddedTests'; import offTests from './offTests'; import onceTests from './onceTests'; import setTests from './setTests'; @@ -21,7 +22,7 @@ import DatabaseContents from '../../support/DatabaseContents'; const testGroups = [ issueSpecificTests, factoryTests, keyTests, parentTests, childTests, rootTests, - pushTests, onTests, onValueTests, offTests, onceTests, updateTests, + pushTests, onTests, onValueTests, onChildAddedTests, offTests, onceTests, updateTests, removeTests, setTests, transactionTests, queryTests, refTests, isEqualTests, ]; diff --git a/tests/src/tests/database/ref/on/onChildAddedTests.js b/tests/src/tests/database/ref/on/onChildAddedTests.js new file mode 100644 index 00000000..0eb80ab5 --- /dev/null +++ b/tests/src/tests/database/ref/on/onChildAddedTests.js @@ -0,0 +1,36 @@ +import 'should-sinon'; +import Promise from 'bluebird'; + +export default function onChildAddedTests({ describe, beforeEach, afterEach, it, firebase }) { + describe('ref().on(\'child_added\')', () => { + describe('the snapshot', () => { + let ref; + let childRef; + let childVal; + beforeEach(async () => { + ref = firebase.native.database().ref('tests/types/object'); + + await new Promise((resolve) => { + ref.on('child_added', (snapshot) => { + childRef = snapshot.ref; + childVal = snapshot.val(); + resolve(); + }); + }); + }); + + afterEach(() => { + ref.off(); + }); + + // https://github.com/invertase/react-native-firebase/issues/221 + it('has a key that identifies the child', () => { + (childRef.key).should.equal('foo'); + }); + + it('has the value of the child', () => { + (childVal).should.equal('bar'); + }); + }); + }); +} diff --git a/tests/src/tests/database/ref/refTests.js b/tests/src/tests/database/ref/refTests.js index 7d3517ec..787bce9d 100644 --- a/tests/src/tests/database/ref/refTests.js +++ b/tests/src/tests/database/ref/refTests.js @@ -1,12 +1,10 @@ function refTests({ describe, it, firebase }) { describe('ref().ref', () => { - it('returns a the reference itself', () => { + it('returns the reference', () => { // Setup - const ref = firebase.native.database().ref(); // Assertion - ref.ref.should.eql(ref); }); });