@@ -18,6 +18,7 @@ beforeEach(async () => {
18
18
b = db . collection ( ) . doc ( )
19
19
c = collection . doc ( )
20
20
d = collection . doc ( )
21
+ await a . update ( { isA : true } )
21
22
await c . update ( { c : true } )
22
23
await d . update ( { ref : c } )
23
24
@@ -31,8 +32,6 @@ beforeEach(async () => {
31
32
} ) ,
32
33
33
34
firestore : {
34
- a,
35
- b,
36
35
c,
37
36
d
38
37
}
@@ -42,17 +41,17 @@ beforeEach(async () => {
42
41
await delay ( 5 )
43
42
} )
44
43
44
+ // NOTE(1) need to wait because we updated with a ref
45
+
45
46
test ( 'binds refs on documents' , async ( ) => {
46
47
// create an empty doc and update using the ref instead of plain data
47
48
const c = collection . doc ( )
48
- await c . update ( { foo : 'foo' } )
49
- await a . update ( { ref : c } )
50
-
51
- // NOTE(1) need to wait because we updated with a ref
52
- await delay ( 5 )
49
+ await c . update ( { isC : true } )
50
+ await b . update ( { ref : c } )
51
+ await vm . $bind ( 'b' , b )
53
52
54
- expect ( vm . a ) . toEqual ( {
55
- ref : { foo : 'foo' }
53
+ expect ( vm . b ) . toEqual ( {
54
+ ref : { isC : true }
56
55
} )
57
56
} )
58
57
@@ -111,7 +110,7 @@ test('update inner ref', async () => {
111
110
} )
112
111
113
112
test ( 'is null if ref does not exist' , async ( ) => {
114
- await d . update ( { ref : a } )
113
+ await d . update ( { ref : b } )
115
114
116
115
// NOTE see #1
117
116
await delay ( 5 )
@@ -138,7 +137,7 @@ test('unbinds previously bound document when overwriting a bound', async () => {
138
137
} )
139
138
// we call update twice to make sure our mock works
140
139
expect ( spy ) . toHaveBeenCalledTimes ( 2 )
141
- await d . update ( { ref : a } )
140
+ await d . update ( { ref : b } )
142
141
// NOTE see #1
143
142
await delay ( 5 )
144
143
@@ -172,33 +171,34 @@ test('does not rebind if it is the same ref', async () => {
172
171
} )
173
172
174
173
test ( 'resolves the promise when refs are resolved in a document' , async ( ) => {
175
- await a . update ( { a : true } )
176
174
await b . update ( { ref : a } )
177
175
178
176
await vm . $bind ( 'item' , b )
179
- expect ( vm . item ) . toEqual ( { ref : { a : true } } )
177
+ expect ( vm . item ) . toEqual ( { ref : { isA : true } } )
180
178
} )
181
179
182
180
test ( 'resolves the promise when nested refs are resolved in a document' , async ( ) => {
183
- await a . update ( { a : b } )
184
- await b . update ( { b : true } )
185
- await d . update ( { ref : a } )
181
+ const item = db . collection ( ) . doc ( )
182
+ await item . update ( { ref : b } )
183
+ await b . update ( { isB : true } )
184
+ await d . update ( { ref : item } )
186
185
187
186
await vm . $bind ( 'item' , d )
188
- expect ( vm . item ) . toEqual ( { ref : { a : { b : true } } } )
187
+ expect ( vm . item ) . toEqual ( { ref : { ref : { isB : true } } } )
189
188
} )
190
189
191
190
test ( 'resolves the promise when nested non-existant refs are resolved in a document' , async ( ) => {
192
- await a . update ( { a : b } )
193
- await d . update ( { ref : a } )
191
+ const item = db . collection ( ) . doc ( )
192
+ await item . update ( { ref : b } )
193
+ await d . update ( { ref : item } )
194
194
195
195
await vm . $bind ( 'item' , d )
196
- expect ( vm . item ) . toEqual ( { ref : { a : null } } )
196
+ expect ( vm . item ) . toEqual ( { ref : { ref : null } } )
197
197
} )
198
198
199
199
test ( 'resolves the promise when the document does not exist' , async ( ) => {
200
200
expect ( vm . item ) . toEqual ( null )
201
- await vm . $bind ( 'item' , a )
201
+ await vm . $bind ( 'item' , b )
202
202
expect ( vm . item ) . toBe ( null )
203
203
} )
204
204
@@ -228,15 +228,14 @@ test('unbinds nested refs when the document is unbound', async () => {
228
228
const cSpy = spyUnbind ( c )
229
229
const dSpy = spyUnbind ( d )
230
230
231
- await a . update ( { a : true } )
232
231
await c . update ( { ref : a } )
233
232
await d . update ( { ref : c } )
234
233
235
234
await vm . $bind ( 'd' , d )
236
235
expect ( vm . d ) . toEqual ( {
237
236
ref : {
238
237
ref : {
239
- a : true
238
+ isA : true
240
239
}
241
240
}
242
241
} )
@@ -258,14 +257,13 @@ test('unbinds multiple refs when the document is unbound', async () => {
258
257
const cSpy = spyUnbind ( c )
259
258
const dSpy = spyUnbind ( d )
260
259
261
- await a . update ( { a : true } )
262
- await c . update ( { c : true } )
260
+ await c . update ( { isC : true } )
263
261
await d . update ( { c, a } )
264
262
265
263
await vm . $bind ( 'd' , d )
266
264
expect ( vm . d ) . toEqual ( {
267
- a : { a : true } ,
268
- c : { c : true }
265
+ a : { isA : true } ,
266
+ c : { isC : true }
269
267
} )
270
268
vm . $unbind ( 'd' )
271
269
@@ -283,8 +281,6 @@ test('unbinds when a ref is replaced', async () => {
283
281
const cSpy = spyUnbind ( c )
284
282
const dSpy = spyUnbind ( d )
285
283
286
- await a . update ( { a : true } )
287
-
288
284
await vm . $bind ( 'd' , d )
289
285
expect ( vm . d ) . toEqual ( {
290
286
ref : {
@@ -297,7 +293,7 @@ test('unbinds when a ref is replaced', async () => {
297
293
await delay ( 5 )
298
294
expect ( vm . d ) . toEqual ( {
299
295
ref : {
300
- a : true
296
+ isA : true
301
297
}
302
298
} )
303
299
@@ -404,3 +400,7 @@ test('properly updates a documen with refs', async () => {
404
400
a : { isA : true }
405
401
} )
406
402
} )
403
+
404
+ test ( 'updates refs in arrays' , async ( ) => {
405
+ const item = db . collection ( ) . doc ( )
406
+ } )
0 commit comments