Skip to content

Commit

Permalink
chore(test): move tests from bind to refs
Browse files Browse the repository at this point in the history
  • Loading branch information
posva committed Dec 11, 2017
1 parent bb4ca0f commit c2b8991
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 37 deletions.
36 changes: 0 additions & 36 deletions test/bind.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,39 +89,3 @@ test('unbinds previously bound refs', async () => {
expect(vm.$firestoreRefs.item).toBe(doc2)
expect(vm.item).toEqual({ bar: 'bar' })
})

test('resolves the promise when refs are resolved in a document', async () => {
const a = db.collection().doc()
await a.update({ a: true })
await document.update({ ref: a })

await vm.$bind('item', document)
expect(vm.item).toEqual({ ref: { a: true }})
})

test('resolves the promise when nested refs are resolved in a document', async () => {
const a = db.collection().doc()
const b = db.collection().doc()
await a.update({ a: b })
await b.update({ b: true })
await document.update({ ref: a })

await vm.$bind('item', document)
expect(vm.item).toEqual({ ref: { a: { b: true }}})
})

test('resolves the promise when nested non-existant refs are resolved in a document', async () => {
const a = db.collection().doc()
const b = db.collection().doc()
await a.update({ a: b })
await document.update({ ref: a })

await vm.$bind('item', document)
expect(vm.item).toEqual({ ref: { a: null }})
})

test('resolves the promise when the document does not exist', async () => {
expect(vm.item).toEqual(null)
await vm.$bind('item', document)
expect(vm.item).toBe(null)
})
34 changes: 33 additions & 1 deletion test/refs.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ beforeEach(async () => {
a: null,
b: null,
c: null,
d: null
d: null,
item: null
}),

firestore: {
Expand Down Expand Up @@ -123,3 +124,34 @@ test('unbinds previously bound document when overwriting a bound', async () => {
})
spy.mockRestore()
})

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

await vm.$bind('item', b)
expect(vm.item).toEqual({ ref: { a: true }})
})

test('resolves the promise when nested refs are resolved in a document', async () => {
await a.update({ a: b })
await b.update({ b: true })
await d.update({ ref: a })

await vm.$bind('item', d)
expect(vm.item).toEqual({ ref: { a: { b: true }}})
})

test('resolves the promise when nested non-existant refs are resolved in a document', async () => {
await a.update({ a: b })
await d.update({ ref: a })

await vm.$bind('item', d)
expect(vm.item).toEqual({ ref: { a: null }})
})

test('resolves the promise when the document does not exist', async () => {
expect(vm.item).toEqual(null)
await vm.$bind('item', a)
expect(vm.item).toBe(null)
})

0 comments on commit c2b8991

Please sign in to comment.