Skip to content

Commit 5dd96c7

Browse files
committed
refactor(test): manually bind refs on tests
1 parent 3e252a0 commit 5dd96c7

File tree

1 file changed

+30
-30
lines changed

1 file changed

+30
-30
lines changed

test/refs-documents.spec.js

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ beforeEach(async () => {
1818
b = db.collection().doc()
1919
c = collection.doc()
2020
d = collection.doc()
21+
await a.update({ isA: true })
2122
await c.update({ c: true })
2223
await d.update({ ref: c })
2324

@@ -31,8 +32,6 @@ beforeEach(async () => {
3132
}),
3233

3334
firestore: {
34-
a,
35-
b,
3635
c,
3736
d
3837
}
@@ -42,17 +41,17 @@ beforeEach(async () => {
4241
await delay(5)
4342
})
4443

44+
// NOTE(1) need to wait because we updated with a ref
45+
4546
test('binds refs on documents', async () => {
4647
// create an empty doc and update using the ref instead of plain data
4748
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)
5352

54-
expect(vm.a).toEqual({
55-
ref: { foo: 'foo' }
53+
expect(vm.b).toEqual({
54+
ref: { isC: true }
5655
})
5756
})
5857

@@ -111,7 +110,7 @@ test('update inner ref', async () => {
111110
})
112111

113112
test('is null if ref does not exist', async () => {
114-
await d.update({ ref: a })
113+
await d.update({ ref: b })
115114

116115
// NOTE see #1
117116
await delay(5)
@@ -138,7 +137,7 @@ test('unbinds previously bound document when overwriting a bound', async () => {
138137
})
139138
// we call update twice to make sure our mock works
140139
expect(spy).toHaveBeenCalledTimes(2)
141-
await d.update({ ref: a })
140+
await d.update({ ref: b })
142141
// NOTE see #1
143142
await delay(5)
144143

@@ -172,33 +171,34 @@ test('does not rebind if it is the same ref', async () => {
172171
})
173172

174173
test('resolves the promise when refs are resolved in a document', async () => {
175-
await a.update({ a: true })
176174
await b.update({ ref: a })
177175

178176
await vm.$bind('item', b)
179-
expect(vm.item).toEqual({ ref: { a: true }})
177+
expect(vm.item).toEqual({ ref: { isA: true }})
180178
})
181179

182180
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 })
186185

187186
await vm.$bind('item', d)
188-
expect(vm.item).toEqual({ ref: { a: { b: true }}})
187+
expect(vm.item).toEqual({ ref: { ref: { isB: true }}})
189188
})
190189

191190
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 })
194194

195195
await vm.$bind('item', d)
196-
expect(vm.item).toEqual({ ref: { a: null }})
196+
expect(vm.item).toEqual({ ref: { ref: null }})
197197
})
198198

199199
test('resolves the promise when the document does not exist', async () => {
200200
expect(vm.item).toEqual(null)
201-
await vm.$bind('item', a)
201+
await vm.$bind('item', b)
202202
expect(vm.item).toBe(null)
203203
})
204204

@@ -228,15 +228,14 @@ test('unbinds nested refs when the document is unbound', async () => {
228228
const cSpy = spyUnbind(c)
229229
const dSpy = spyUnbind(d)
230230

231-
await a.update({ a: true })
232231
await c.update({ ref: a })
233232
await d.update({ ref: c })
234233

235234
await vm.$bind('d', d)
236235
expect(vm.d).toEqual({
237236
ref: {
238237
ref: {
239-
a: true
238+
isA: true
240239
}
241240
}
242241
})
@@ -258,14 +257,13 @@ test('unbinds multiple refs when the document is unbound', async () => {
258257
const cSpy = spyUnbind(c)
259258
const dSpy = spyUnbind(d)
260259

261-
await a.update({ a: true })
262-
await c.update({ c: true })
260+
await c.update({ isC: true })
263261
await d.update({ c, a })
264262

265263
await vm.$bind('d', d)
266264
expect(vm.d).toEqual({
267-
a: { a: true },
268-
c: { c: true }
265+
a: { isA: true },
266+
c: { isC: true }
269267
})
270268
vm.$unbind('d')
271269

@@ -283,8 +281,6 @@ test('unbinds when a ref is replaced', async () => {
283281
const cSpy = spyUnbind(c)
284282
const dSpy = spyUnbind(d)
285283

286-
await a.update({ a: true })
287-
288284
await vm.$bind('d', d)
289285
expect(vm.d).toEqual({
290286
ref: {
@@ -297,7 +293,7 @@ test('unbinds when a ref is replaced', async () => {
297293
await delay(5)
298294
expect(vm.d).toEqual({
299295
ref: {
300-
a: true
296+
isA: true
301297
}
302298
})
303299

@@ -404,3 +400,7 @@ test('properly updates a documen with refs', async () => {
404400
a: { isA: true }
405401
})
406402
})
403+
404+
test('updates refs in arrays', async () => {
405+
const item = db.collection().doc()
406+
})

0 commit comments

Comments
 (0)