@firebase/database-compat 0.1.1-2021823172527 → 0.1.2-canary.0b3ca78eb

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/CHANGELOG.md +19 -8
  2. package/dist/database-compat/src/index.d.ts +0 -9
  3. package/dist/database-compat/src/index.node.d.ts +0 -53
  4. package/dist/database-compat/src/index.standalone.d.ts +52 -0
  5. package/dist/index.esm2017.js +5 -6
  6. package/dist/index.esm2017.js.map +1 -1
  7. package/dist/index.esm5.js +2 -3
  8. package/dist/index.esm5.js.map +1 -1
  9. package/dist/index.js +10 -77
  10. package/dist/index.js.map +1 -1
  11. package/dist/index.standalone.js +15150 -0
  12. package/dist/index.standalone.js.map +1 -0
  13. package/dist/node-esm/database-compat/src/api/Database.d.ts +72 -0
  14. package/dist/node-esm/database-compat/src/api/Reference.d.ts +201 -0
  15. package/{karma.conf.js → dist/node-esm/database-compat/src/api/TransactionResult.d.ts} +26 -34
  16. package/dist/node-esm/database-compat/src/api/internal.d.ts +39 -0
  17. package/dist/node-esm/database-compat/src/api/onDisconnect.d.ts +27 -0
  18. package/dist/node-esm/database-compat/src/index.d.ts +32 -0
  19. package/dist/node-esm/database-compat/src/index.node.d.ts +14 -0
  20. package/dist/node-esm/database-compat/src/index.standalone.d.ts +52 -0
  21. package/{src/util/util.ts → dist/node-esm/database-compat/src/util/util.d.ts} +17 -25
  22. package/dist/node-esm/database-compat/src/util/validation.d.ts +18 -0
  23. package/{src/api/TransactionResult.ts → dist/node-esm/database-compat/test/browser/crawler_support.test.d.ts} +17 -34
  24. package/dist/node-esm/database-compat/test/database.test.d.ts +17 -0
  25. package/dist/node-esm/database-compat/test/datasnapshot.test.d.ts +17 -0
  26. package/dist/node-esm/database-compat/test/helpers/events.d.ts +34 -0
  27. package/dist/node-esm/database-compat/test/helpers/util.d.ts +42 -0
  28. package/dist/node-esm/database-compat/test/info.test.d.ts +17 -0
  29. package/dist/node-esm/database-compat/test/order.test.d.ts +17 -0
  30. package/dist/node-esm/database-compat/test/order_by.test.d.ts +17 -0
  31. package/dist/node-esm/database-compat/test/promise.test.d.ts +17 -0
  32. package/dist/node-esm/database-compat/test/query.test.d.ts +17 -0
  33. package/dist/node-esm/database-compat/test/servervalues.test.d.ts +17 -0
  34. package/dist/node-esm/database-compat/test/transaction.test.d.ts +17 -0
  35. package/dist/node-esm/index.js +868 -0
  36. package/dist/node-esm/index.js.map +1 -0
  37. package/dist/node-esm/package.json +1 -0
  38. package/package.json +34 -9
  39. package/standalone/package.json +7 -0
  40. package/.eslintrc.js +0 -64
  41. package/rollup.config.js +0 -125
  42. package/src/api/Database.ts +0 -123
  43. package/src/api/Reference.ts +0 -790
  44. package/src/api/internal.ts +0 -91
  45. package/src/api/onDisconnect.ts +0 -112
  46. package/src/index.node.ts +0 -142
  47. package/src/index.ts +0 -88
  48. package/src/util/validation.ts +0 -59
  49. package/test/browser/crawler_support.test.ts +0 -206
  50. package/test/database.test.ts +0 -306
  51. package/test/datasnapshot.test.ts +0 -249
  52. package/test/helpers/events.ts +0 -258
  53. package/test/helpers/util.ts +0 -177
  54. package/test/info.test.ts +0 -222
  55. package/test/order.test.ts +0 -592
  56. package/test/order_by.test.ts +0 -530
  57. package/test/promise.test.ts +0 -261
  58. package/test/query.test.ts +0 -4670
  59. package/test/servervalues.test.ts +0 -152
  60. package/test/transaction.test.ts +0 -1534
  61. package/tsconfig.json +0 -11
@@ -1,306 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright 2017 Google LLC
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- * http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- */
17
-
18
- import firebase from '@firebase/app-compat';
19
- import { expect } from 'chai';
20
-
21
- import { DATABASE_ADDRESS, createTestApp } from './helpers/util';
22
- import '../src/index';
23
-
24
- describe('Database Tests', () => {
25
- let defaultApp;
26
-
27
- beforeEach(() => {
28
- defaultApp = createTestApp();
29
- });
30
-
31
- afterEach(() => {
32
- return defaultApp.delete();
33
- });
34
-
35
- it('Can get database.', () => {
36
- const db = (firebase as any).database();
37
- expect(db).to.not.be.undefined;
38
- expect(db).not.to.be.null;
39
- });
40
-
41
- it('Can get database with custom URL', () => {
42
- const db = defaultApp.database('http://foo.bar.com');
43
- expect(db).to.be.ok;
44
- // The URL is assumed to be secure if no port is specified.
45
- expect(db.ref().toString()).to.equal('https://foo.bar.com/');
46
- });
47
-
48
- it('Can get database with custom URL and port', () => {
49
- const db = defaultApp.database('http://foo.bar.com:80');
50
- expect(db).to.be.ok;
51
- expect(db.ref().toString()).to.equal('http://foo.bar.com:80/');
52
- });
53
-
54
- it('Can get database with https URL', () => {
55
- const db = defaultApp.database('https://foo.bar.com');
56
- expect(db).to.be.ok;
57
- expect(db.ref().toString()).to.equal('https://foo.bar.com/');
58
- });
59
-
60
- it('Can get database with multi-region URL', () => {
61
- const db = defaultApp.database('http://foo.euw1.firebasedatabase.app');
62
- expect(db).to.be.ok;
63
- expect(db._delegate._repo.repoInfo_.namespace).to.equal('foo');
64
- expect(db.ref().toString()).to.equal(
65
- 'https://foo.euw1.firebasedatabase.app/'
66
- );
67
- });
68
-
69
- it('Can get database with upper case URL', () => {
70
- const db = defaultApp.database('http://fOO.EUW1.firebaseDATABASE.app');
71
- expect(db).to.be.ok;
72
- expect(db._delegate._repo.repoInfo_.namespace).to.equal('foo');
73
- expect(db.ref().toString()).to.equal(
74
- 'https://foo.euw1.firebasedatabase.app/'
75
- );
76
- });
77
-
78
- it('Can get database with localhost URL', () => {
79
- const db = defaultApp.database('http://localhost');
80
- expect(db).to.be.ok;
81
- expect(db.ref().toString()).to.equal('https://localhost/');
82
- });
83
-
84
- it('Can get database with localhost URL and port', () => {
85
- const db = defaultApp.database('http://localhost:80');
86
- expect(db).to.be.ok;
87
- expect(db.ref().toString()).to.equal('http://localhost:80/');
88
- });
89
-
90
- it('Can get database with a upper case localhost URL', () => {
91
- const db = defaultApp.database('http://LOCALHOST');
92
- expect(db).to.be.ok;
93
- expect(db.ref().toString()).to.equal('https://localhost/');
94
- });
95
-
96
- it('Can get database with a upper case localhost URL and ns', () => {
97
- const db = defaultApp.database('http://LOCALHOST?ns=foo');
98
- expect(db).to.be.ok;
99
- expect(db._delegate._repo.repoInfo_.namespace).to.equal('foo');
100
- expect(db.ref().toString()).to.equal('https://localhost/');
101
- });
102
-
103
- it('Can infer database URL from project Id', async () => {
104
- const app = firebase.initializeApp(
105
- { projectId: 'abc123' },
106
- 'project-id-app'
107
- );
108
- const db = app.database();
109
- expect(db).to.be.ok;
110
- // The URL is assumed to be secure if no port is specified.
111
- expect(db.ref().toString()).to.equal(
112
- 'https://abc123-default-rtdb.firebaseio.com/'
113
- );
114
- await app.delete();
115
- });
116
-
117
- it('Can read ns query param', () => {
118
- const db = defaultApp.database('http://localhost:80/?ns=foo&unused=true');
119
- expect(db).to.be.ok;
120
- expect(db._delegate._repo.repoInfo_.namespace).to.equal('foo');
121
- expect(db.ref().toString()).to.equal('http://localhost:80/');
122
- });
123
-
124
- it('Reads ns query param even when subdomain is set', () => {
125
- const db = defaultApp.database('http://bar.firebaseio.com?ns=foo');
126
- expect(db).to.be.ok;
127
- expect(db._delegate._repo.repoInfo_.namespace).to.equal('foo');
128
- expect(db.ref().toString()).to.equal('https://bar.firebaseio.com/');
129
- });
130
-
131
- it('Interprets FIREBASE_DATABASE_EMULATOR_HOST var correctly', () => {
132
- process.env['FIREBASE_DATABASE_EMULATOR_HOST'] = 'localhost:9000';
133
- const db = defaultApp.database('https://bar.firebaseio.com');
134
- expect(db).to.be.ok;
135
- expect(db._delegate._repo.repoInfo_.namespace).to.equal('bar');
136
- expect(db._delegate._repo.repoInfo_.host).to.equal('localhost:9000');
137
- delete process.env['FIREBASE_DATABASE_EMULATOR_HOST'];
138
- });
139
-
140
- it('Different instances for different URLs', () => {
141
- const db1 = defaultApp.database('http://foo1.bar.com');
142
- const db2 = defaultApp.database('http://foo2.bar.com');
143
- expect(db1.ref().toString()).to.equal('https://foo1.bar.com/');
144
- expect(db2.ref().toString()).to.equal('https://foo2.bar.com/');
145
- });
146
-
147
- it('Different instances for different URLs (with FIREBASE_DATABASE_EMULATOR_HOST)', () => {
148
- process.env['FIREBASE_DATABASE_EMULATOR_HOST'] = 'localhost:9000';
149
- const db1 = defaultApp.database('http://foo1.bar.com');
150
- const db2 = defaultApp.database('http://foo2.bar.com');
151
- expect(db1._delegate._repo.repoInfo_.toURLString()).to.equal(
152
- 'http://localhost:9000/?ns=foo1'
153
- );
154
- expect(db2._delegate._repo.repoInfo_.toURLString()).to.equal(
155
- 'http://localhost:9000/?ns=foo2'
156
- );
157
- delete process.env['FIREBASE_DATABASE_EMULATOR_HOST'];
158
- });
159
-
160
- it('Cannot use same URL twice', () => {
161
- defaultApp.database('http://foo.bar.com');
162
- expect(() => {
163
- defaultApp.database('http://foo.bar.com/');
164
- }).to.throw(/Database initialized multiple times/i);
165
- });
166
-
167
- it('Cannot use same URL twice (with FIREBASE_DATABASE_EMULATOR_HOST)', () => {
168
- process.env['FIREBASE_DATABASE_EMULATOR_HOST'] = 'localhost:9000';
169
- defaultApp.database('http://foo.bar.com');
170
- expect(() => {
171
- defaultApp.database('http://foo.bar.com/');
172
- }).to.throw(/Database initialized multiple times/i);
173
- delete process.env['FIREBASE_DATABASE_EMULATOR_HOST'];
174
- });
175
-
176
- it('Databases with legacy domain', () => {
177
- expect(() => {
178
- defaultApp.database('http://foo.firebase.com/');
179
- }).to.throw(/is no longer supported/i);
180
- });
181
-
182
- it('Databases with invalid custom URLs', () => {
183
- expect(() => {
184
- defaultApp.database('not-a-url');
185
- }).to.throw(/Cannot parse Firebase url/i);
186
- expect(() => {
187
- defaultApp.database('http://foo.com');
188
- }).to.throw(/Cannot parse Firebase url/i);
189
- expect(() => {
190
- defaultApp.database('http://fblocal.com');
191
- }).to.throw(/Cannot parse Firebase url/i);
192
- expect(() => {
193
- defaultApp.database('http://x.fblocal.com:9000/paths/are/bad');
194
- }).to.throw(/Database URL must point to the root of a Firebase Database/i);
195
- });
196
-
197
- it('Can get app', () => {
198
- const db = (firebase as any).database();
199
- expect(db.app).to.not.be.undefined;
200
- expect((db.app as any) instanceof firebase.app.App);
201
- });
202
-
203
- it('Can get root ref', () => {
204
- const db = (firebase as any).database();
205
-
206
- const ref = db.ref();
207
-
208
- expect(ref instanceof (firebase as any).database.Reference).to.be.true;
209
- expect(ref.key).to.be.null;
210
- });
211
-
212
- it('Can get child ref', () => {
213
- const db = (firebase as any).database();
214
-
215
- const ref = db.ref('child');
216
-
217
- expect(ref instanceof (firebase as any).database.Reference).to.be.true;
218
- expect(ref.key).to.equal('child');
219
- });
220
-
221
- it('Can get deep child ref', () => {
222
- const db = (firebase as any).database();
223
-
224
- const ref = db.ref('child/grand-child');
225
-
226
- expect(ref instanceof (firebase as any).database.Reference).to.be.true;
227
- expect(ref.key).to.equal('grand-child');
228
- });
229
-
230
- it('Can get ref from ref', () => {
231
- const db1 = (firebase as any).database();
232
- const db2 = (firebase as any).database();
233
-
234
- const ref1 = db1.ref('child');
235
- const ref2 = db2.ref(ref1);
236
-
237
- expect(ref1.key).to.equal('child');
238
- expect(ref2.key).to.equal('child');
239
- });
240
-
241
- it('ref() validates arguments', () => {
242
- const db = (firebase as any).database();
243
- expect(() => {
244
- const ref = (db as any).ref('path', 'extra');
245
- }).to.throw(/Expects no more than 1/);
246
- });
247
-
248
- it('ref() validates project', () => {
249
- const db1 = defaultApp.database('http://bar.firebaseio.com');
250
- const db2 = defaultApp.database('http://foo.firebaseio.com');
251
-
252
- const ref1 = db1.ref('child');
253
-
254
- expect(() => {
255
- db2.ref(ref1);
256
- }).to.throw(/does not match.*database/i);
257
- });
258
-
259
- it('Can get refFromURL()', () => {
260
- const db = (firebase as any).database();
261
- const ref = db.refFromURL(DATABASE_ADDRESS + '/path/to/data');
262
- expect(ref.key).to.equal('data');
263
- });
264
-
265
- it('refFromURL() validates domain', () => {
266
- const db = (firebase as any)
267
- .app()
268
- .database('https://thisisreal.firebaseio.com');
269
- expect(() =>
270
- db.refFromURL('https://thisisnotreal.firebaseio.com/path/to/data')
271
- ).to.throw(/does not match.*database/i);
272
- });
273
-
274
- it('refFromURL() validates argument', () => {
275
- const db = (firebase as any).database();
276
- expect(() => {
277
- const ref = (db as any).refFromURL();
278
- }).to.throw(/Expects at least 1/);
279
- });
280
-
281
- it('can call useEmulator before use', () => {
282
- const db = (firebase as any).database();
283
- db.useEmulator('localhost', 1234);
284
- expect(db.ref().toString()).to.equal('http://localhost:1234/');
285
- });
286
-
287
- it('cannot call useEmulator after use', () => {
288
- const db = (firebase as any).database();
289
-
290
- db.ref().set({
291
- hello: 'world'
292
- });
293
-
294
- expect(() => {
295
- db.useEmulator('localhost', 1234);
296
- }).to.throw(/Cannot call useEmulator/);
297
- });
298
-
299
- it('refFromURL returns an emulated ref with useEmulator', () => {
300
- const db = (firebase as any).database();
301
- db.useEmulator('localhost', 1234);
302
-
303
- const ref = db.refFromURL(DATABASE_ADDRESS + '/path/to/data');
304
- expect(ref.toString()).to.equal(`http://localhost:1234/path/to/data`);
305
- });
306
- });
@@ -1,249 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright 2017 Google LLC
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- * http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- */
17
-
18
-
19
- import { DataSnapshot as ExpDataSnapshot } from '@firebase/database';
20
- import { expect } from 'chai';
21
-
22
- import { PRIORITY_INDEX } from '../../database/src/core/snap/indexes/PriorityIndex';
23
- import { nodeFromJSON } from '../../database/src/core/snap/nodeFromJSON';
24
- import { DataSnapshot, Reference } from '../src/api/Reference';
25
-
26
- import { getRandomNode } from './helpers/util';
27
-
28
- describe('DataSnapshot Tests', () => {
29
- /** @returns {!DataSnapshot} */
30
- const snapshotForJSON = function (json) {
31
- const dummyRef = getRandomNode() as Reference;
32
- return new DataSnapshot(
33
- dummyRef.database,
34
- new ExpDataSnapshot(
35
- nodeFromJSON(json),
36
- dummyRef._delegate,
37
- PRIORITY_INDEX
38
- )
39
- );
40
- };
41
-
42
- it('DataSnapshot.hasChildren() works.', () => {
43
- let snap = snapshotForJSON({});
44
- expect(snap.hasChildren()).to.equal(false);
45
-
46
- snap = snapshotForJSON(5);
47
- expect(snap.hasChildren()).to.equal(false);
48
-
49
- snap = snapshotForJSON({ x: 5 });
50
- expect(snap.hasChildren()).to.equal(true);
51
- });
52
-
53
- it('DataSnapshot.exists() works.', () => {
54
- let snap = snapshotForJSON({});
55
- expect(snap.exists()).to.equal(false);
56
-
57
- snap = snapshotForJSON({ '.priority': 1 });
58
- expect(snap.exists()).to.equal(false);
59
-
60
- snap = snapshotForJSON(null);
61
- expect(snap.exists()).to.equal(false);
62
-
63
- snap = snapshotForJSON(true);
64
- expect(snap.exists()).to.equal(true);
65
-
66
- snap = snapshotForJSON(5);
67
- expect(snap.exists()).to.equal(true);
68
-
69
- snap = snapshotForJSON({ x: 5 });
70
- expect(snap.exists()).to.equal(true);
71
- });
72
-
73
- it('DataSnapshot.val() works.', () => {
74
- let snap = snapshotForJSON(5);
75
- expect(snap.val()).to.equal(5);
76
-
77
- snap = snapshotForJSON({});
78
- expect(snap.val()).to.equal(null);
79
-
80
- const json = {
81
- x: 5,
82
- y: {
83
- ya: 1,
84
- yb: 2,
85
- yc: { yca: 3 }
86
- }
87
- };
88
- snap = snapshotForJSON(json);
89
- expect(snap.val()).to.deep.equal(json);
90
- });
91
-
92
- it('DataSnapshot.child() works.', () => {
93
- const snap = snapshotForJSON({ x: 5, y: { yy: 3, yz: 4 } });
94
- expect(snap.child('x').val()).to.equal(5);
95
- expect(snap.child('y').val()).to.deep.equal({ yy: 3, yz: 4 });
96
- expect(snap.child('y').child('yy').val()).to.equal(3);
97
- expect(snap.child('y/yz').val()).to.equal(4);
98
- expect(snap.child('z').val()).to.equal(null);
99
- expect(snap.child('x/y').val()).to.equal(null);
100
- expect(snap.child('x').child('y').val()).to.equal(null);
101
- });
102
-
103
- it('DataSnapshot.hasChild() works.', () => {
104
- const snap = snapshotForJSON({ x: 5, y: { yy: 3, yz: 4 } });
105
- expect(snap.hasChild('x')).to.equal(true);
106
- expect(snap.hasChild('y/yy')).to.equal(true);
107
- expect(snap.hasChild('dinosaur')).to.equal(false);
108
- expect(snap.child('x').hasChild('anything')).to.equal(false);
109
- expect(snap.hasChild('x/anything/at/all')).to.equal(false);
110
- });
111
-
112
- it('DataSnapshot.key works.', () => {
113
- const snap = snapshotForJSON({ a: { b: { c: 5 } } });
114
- expect(snap.child('a').key).to.equal('a');
115
- expect(snap.child('a/b/c').key).to.equal('c');
116
- expect(snap.child('/a/b/c/').key).to.equal('c');
117
- expect(snap.child('////a////b/c///').key).to.equal('c');
118
- expect(snap.child('///').key).to.equal(snap.key);
119
-
120
- // Should also work for nonexistent paths.
121
- expect(snap.child('/z/q/r/v/m').key).to.equal('m');
122
- });
123
-
124
- it('DataSnapshot.forEach() works: no priorities.', () => {
125
- const snap = snapshotForJSON({
126
- a: 1,
127
- z: 26,
128
- m: 13,
129
- n: 14,
130
- c: 3,
131
- b: 2,
132
- e: 5
133
- });
134
- let out = '';
135
- snap.forEach(child => {
136
- out = out + child.key + ':' + child.val() + ':';
137
- });
138
-
139
- expect(out).to.equal('a:1:b:2:c:3:e:5:m:13:n:14:z:26:');
140
- });
141
-
142
- it('DataSnapshot.forEach() works: numeric priorities.', () => {
143
- const snap = snapshotForJSON({
144
- a: { '.value': 1, '.priority': 26 },
145
- z: { '.value': 26, '.priority': 1 },
146
- m: { '.value': 13, '.priority': 14 },
147
- n: { '.value': 14, '.priority': 12 },
148
- c: { '.value': 3, '.priority': 24 },
149
- b: { '.value': 2, '.priority': 25 },
150
- e: { '.value': 5, '.priority': 22 }
151
- });
152
-
153
- let out = '';
154
- snap.forEach(child => {
155
- out = out + child.key + ':' + child.val() + ':';
156
- });
157
-
158
- expect(out).to.equal('z:26:n:14:m:13:e:5:c:3:b:2:a:1:');
159
- });
160
-
161
- it('DataSnapshot.forEach() works: numeric priorities as strings.', () => {
162
- const snap = snapshotForJSON({
163
- a: { '.value': 1, '.priority': '26' },
164
- z: { '.value': 26, '.priority': '1' },
165
- m: { '.value': 13, '.priority': '14' },
166
- n: { '.value': 14, '.priority': '12' },
167
- c: { '.value': 3, '.priority': '24' },
168
- b: { '.value': 2, '.priority': '25' },
169
- e: { '.value': 5, '.priority': '22' }
170
- });
171
-
172
- let out = '';
173
- snap.forEach(child => {
174
- out = out + child.key + ':' + child.val() + ':';
175
- });
176
-
177
- expect(out).to.equal('z:26:n:14:m:13:e:5:c:3:b:2:a:1:');
178
- });
179
-
180
- it('DataSnapshot.forEach() works: alpha priorities.', () => {
181
- const snap = snapshotForJSON({
182
- a: { '.value': 1, '.priority': 'first' },
183
- z: { '.value': 26, '.priority': 'second' },
184
- m: { '.value': 13, '.priority': 'third' },
185
- n: { '.value': 14, '.priority': 'fourth' },
186
- c: { '.value': 3, '.priority': 'fifth' },
187
- b: { '.value': 2, '.priority': 'sixth' },
188
- e: { '.value': 5, '.priority': 'seventh' }
189
- });
190
-
191
- let out = '';
192
- snap.forEach(child => {
193
- out = out + child.key + ':' + child.val() + ':';
194
- });
195
-
196
- expect(out).to.equal('c:3:a:1:n:14:z:26:e:5:b:2:m:13:');
197
- });
198
-
199
- it('DataSnapshot.foreach() works: mixed alpha and numeric priorities', () => {
200
- const json = {
201
- alpha42: { '.value': 1, '.priority': 'zed' },
202
- noPriorityC: { '.value': 1, '.priority': null },
203
- num41: { '.value': 1, '.priority': 500 },
204
- noPriorityB: { '.value': 1, '.priority': null },
205
- num80: { '.value': 1, '.priority': 4000.1 },
206
- num50: { '.value': 1, '.priority': 4000 },
207
- num10: { '.value': 1, '.priority': 24 },
208
- alpha41: { '.value': 1, '.priority': 'zed' },
209
- alpha20: { '.value': 1, '.priority': 'horse' },
210
- num20: { '.value': 1, '.priority': 123 },
211
- num70: { '.value': 1, '.priority': 4000.01 },
212
- noPriorityA: { '.value': 1, '.priority': null },
213
- alpha30: { '.value': 1, '.priority': 'tree' },
214
- num30: { '.value': 1, '.priority': 300 },
215
- num60: { '.value': 1, '.priority': 4000.001 },
216
- alpha10: { '.value': 1, '.priority': '0horse' },
217
- num42: { '.value': 1, '.priority': 500 },
218
- alpha40: { '.value': 1, '.priority': 'zed' },
219
- num40: { '.value': 1, '.priority': 500 }
220
- };
221
-
222
- const snap = snapshotForJSON(json);
223
- let out = '';
224
- snap.forEach(child => {
225
- out = out + child.key + ', ';
226
- });
227
-
228
- expect(out).to.equal(
229
- 'noPriorityA, noPriorityB, noPriorityC, num10, num20, num30, num40, num41, num42, num50, num60, num70, num80, alpha10, alpha20, alpha30, alpha40, alpha41, alpha42, '
230
- );
231
- });
232
-
233
- it('.val() exports array-like data as arrays.', () => {
234
- const array = ['bob', 'and', 'becky', 'seem', 'really', 'nice', 'yeah?'];
235
- const snap = snapshotForJSON(array);
236
- const snapVal = snap.val();
237
- expect(snapVal).to.deep.equal(array);
238
- expect(snapVal instanceof Array).to.equal(true); // to.equal doesn't verify type.
239
- });
240
-
241
- it('DataSnapshot can be JSON serialized', () => {
242
- const json = {
243
- foo: 'bar',
244
- '.priority': 1
245
- };
246
- const snap = snapshotForJSON(json);
247
- expect(JSON.parse(JSON.stringify(snap))).to.deep.equal(json);
248
- });
249
- });