File tree Expand file tree Collapse file tree 2 files changed +25
-11
lines changed Expand file tree Collapse file tree 2 files changed +25
-11
lines changed Original file line number Diff line number Diff line change @@ -4,7 +4,8 @@ function bindCollection ({
44 vm,
55 key,
66 collection,
7- resolve
7+ resolve,
8+ reject
89} ) {
910 // TODO wait to get all data
1011 const array = vm [ key ] = [ ]
@@ -34,16 +35,15 @@ function bindCollection ({
3435 ready = true
3536 resolve ( array )
3637 }
37- } , err => {
38- console . log ( 'onSnapshot ERR' , err )
39- } )
38+ } , reject )
4039}
4140
4241function bindDocument ( {
4342 vm,
4443 key,
4544 document,
46- resolve
45+ resolve,
46+ reject
4747} ) {
4848 // TODO warning check if key exists?
4949 // TODO create boundRefs object
@@ -68,29 +68,29 @@ function bindDocument ({
6868 // console.log('ref snap', doc)
6969 // }, err => console.log('onSnapshot ref ERR', err))
7070 // }
71- } , err => {
72- console . log ( 'onSnapshot ERR' , err )
73- } )
71+ } , reject )
7472
7573 // TODO return a custom unbind function that unbind all refs
7674}
7775
7876function bind ( { vm, key, ref } ) {
79- return new Promise ( resolve => {
77+ return new Promise ( ( resolve , reject ) => {
8078 let unbind
8179 if ( ref . where ) {
8280 unbind = bindCollection ( {
8381 vm,
8482 key,
8583 collection : ref ,
86- resolve
84+ resolve,
85+ reject
8786 } )
8887 } else {
8988 unbind = bindDocument ( {
9089 vm,
9190 key,
9291 document : ref ,
93- resolve
92+ resolve,
93+ reject
9494 } )
9595 }
9696 vm . _firestoreUnbinds [ key ] = unbind
Original file line number Diff line number Diff line change 11import test from 'ava'
2+ import sinon from 'sinon'
23import Vuefire from '../src'
34import {
45 db ,
@@ -50,3 +51,16 @@ test('returs a promise', t => {
5051 t . true ( vm . $bind ( 'items' , collection ) instanceof Promise )
5152 t . true ( vm . $bind ( 'item' , document ) instanceof Promise )
5253} )
54+
55+ test ( 'rejects the promise when errors' , async t => {
56+ const { vm, document, collection } = t . context
57+ const fakeOnSnapshot = ( _ , fail ) => {
58+ fail ( new Error ( 'nope' ) )
59+ }
60+ sinon . stub ( document , 'onSnapshot' ) . callsFake ( fakeOnSnapshot )
61+ sinon . stub ( collection , 'onSnapshot' ) . callsFake ( fakeOnSnapshot )
62+ await t . throws ( vm . $bind ( 'items' , collection ) )
63+ await t . throws ( vm . $bind ( 'item' , document ) )
64+ document . onSnapshot . restore ( )
65+ collection . onSnapshot . restore ( )
66+ } )
You can’t perform that action at this time.
0 commit comments