|
16 | 16 | */
|
17 | 17 |
|
18 | 18 | import { expect } from 'chai';
|
19 |
| -import { getRandomNode } from './helpers/util'; |
| 19 | +import { getFreshRepoFromReference, getRandomNode } from './helpers/util'; |
20 | 20 | import { Database } from '../src/api/Database';
|
21 | 21 | import { Reference } from '../src/api/Reference';
|
22 | 22 | import { nodeFromJSON } from '../src/core/snap/nodeFromJSON';
|
@@ -46,50 +46,51 @@ describe('ServerValue tests', () => {
|
46 | 46 | // Ensure that increments don't explode when the SyncTree must return a null
|
47 | 47 | // node (i.e. ChildrenNode.EMPTY_NODE) because there is not yet any synced
|
48 | 48 | // data.
|
49 |
| - const node = getRandomNode() as Reference; |
| 49 | + // TODO(b/146657568): Remove getFreshRepoFromReference() call and goOffline() |
| 50 | + // once we have emulator support. We can also await the set() call. |
| 51 | + const node = getFreshRepoFromReference(getRandomNode()) as Reference; |
| 52 | + node.database.goOffline(); |
| 53 | + |
50 | 54 | const addOne = Database.ServerValue._increment(1);
|
51 | 55 |
|
52 | 56 | node.set(addOne);
|
53 | 57 | });
|
54 | 58 |
|
55 | 59 | it('handles increments locally', async () => {
|
56 |
| - const node = getRandomNode() as Reference; |
| 60 | + // TODO(b/146657568): Remove getFreshRepoFromReference() call and goOffline() |
| 61 | + // once we have emulator support. We can also await the set() calls. |
| 62 | + const node = getFreshRepoFromReference(getRandomNode()) as Reference; |
| 63 | + node.database.goOffline(); |
| 64 | + |
57 | 65 | const addOne = Database.ServerValue._increment(1);
|
58 | 66 |
|
59 |
| - // Must go offline because the latest emulator may not support this server op |
60 |
| - // This also means we can't await node operations, which would block the test. |
61 |
| - node.database.goOffline(); |
62 |
| - try { |
63 |
| - const values: any[] = []; |
64 |
| - const expected: any[] = []; |
65 |
| - node.on('value', snap => values.push(snap.val())); |
| 67 | + const values: any = []; |
| 68 | + const expected: any = []; |
| 69 | + node.on('value', snap => values.push(snap.val())); |
66 | 70 |
|
67 |
| - // null -> increment(x) = x |
68 |
| - node.set(addOne); |
69 |
| - expected.push(1); |
| 71 | + // null -> increment(x) = x |
| 72 | + node.set(addOne); |
| 73 | + expected.push(1); |
70 | 74 |
|
71 |
| - // x -> increment(y) = x + y |
72 |
| - node.set(5); |
73 |
| - node.set(addOne); |
74 |
| - expected.push(5); |
75 |
| - expected.push(6); |
| 75 | + // x -> increment(y) = x + y |
| 76 | + node.set(5); |
| 77 | + node.set(addOne); |
| 78 | + expected.push(5); |
| 79 | + expected.push(6); |
76 | 80 |
|
77 |
| - // str -> increment(x) = x |
78 |
| - node.set('hello'); |
79 |
| - node.set(addOne); |
80 |
| - expected.push('hello'); |
81 |
| - expected.push(1); |
| 81 | + // str -> increment(x) = x |
| 82 | + node.set('hello'); |
| 83 | + node.set(addOne); |
| 84 | + expected.push('hello'); |
| 85 | + expected.push(1); |
82 | 86 |
|
83 |
| - // obj -> increment(x) = x |
84 |
| - node.set({ 'hello': 'world' }); |
85 |
| - node.set(addOne); |
86 |
| - expected.push({ 'hello': 'world' }); |
87 |
| - expected.push(1); |
| 87 | + // obj -> increment(x) = x |
| 88 | + node.set({ 'hello': 'world' }); |
| 89 | + node.set(addOne); |
| 90 | + expected.push({ 'hello': 'world' }); |
| 91 | + expected.push(1); |
88 | 92 |
|
89 |
| - node.off('value'); |
90 |
| - expect(values).to.deep.equal(expected); |
91 |
| - } finally { |
92 |
| - node.database.goOnline(); |
93 |
| - } |
| 93 | + node.off('value'); |
| 94 | + expect(values).to.deep.equal(expected); |
94 | 95 | });
|
95 | 96 | });
|
0 commit comments