File tree Expand file tree Collapse file tree 4 files changed +56
-57
lines changed Expand file tree Collapse file tree 4 files changed +56
-57
lines changed Original file line number Diff line number Diff line change 1- export * from './wait-for-update'
1+ import Vue from 'vue'
2+
3+ Vue . config . productionTip = false
4+ export { Vue }
5+
26export * from './mock'
7+
8+ export function spyUnbind ( ref ) {
9+ const spy = jest . fn ( )
10+ const onSnapshot = ref . onSnapshot . bind ( ref )
11+ ref . onSnapshot = fn => {
12+ const unbind = onSnapshot ( fn )
13+ return ( ) => {
14+ spy ( )
15+ unbind ( )
16+ }
17+ }
18+ return spy
19+ }
20+
21+ export function spyOnSnapshot ( ref ) {
22+ const onSnapshot = ref . onSnapshot . bind ( ref )
23+ return ( ref . onSnapshot = jest . fn ( ( ...args ) => onSnapshot ( ...args ) ) )
24+ }
25+
26+ export function spyOnSnapshotCallback ( ref ) {
27+ const onSnapshot = ref . onSnapshot . bind ( ref )
28+ const spy = jest . fn ( )
29+ ref . onSnapshot = fn => onSnapshot ( ( ...args ) => {
30+ spy ( )
31+ fn ( ...args )
32+ } )
33+ return spy
34+ }
35+
36+ // This makes sure some tests fail by delaying callbacks
37+ export function delayUpdate ( ref , time = 0 ) {
38+ const onSnapshot = ref . onSnapshot . bind ( ref )
39+ ref . onSnapshot = fn => onSnapshot ( async ( ...args ) => {
40+ await delay ( time )
41+ fn ( ...args )
42+ } )
43+ }
44+
45+ export function tick ( ) {
46+ return new Promise ( ( resolve , reject ) => {
47+ Vue . nextTick ( resolve )
48+ } )
49+ }
50+
51+ export function delay ( time ) {
52+ return new Promise ( resolve => setTimeout ( resolve , time ) )
53+ }
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 33 db ,
44 tick ,
55 delay ,
6+ delayUpdate ,
67 Vue
78} from './helpers'
89
@@ -26,15 +27,6 @@ beforeEach(async () => {
2627 await tick ( )
2728} )
2829
29- // This makes sure some tests fail by delaying callbacks
30- function delayUpdate ( ref , time = 0 ) {
31- const onSnapshot = ref . onSnapshot . bind ( ref )
32- ref . onSnapshot = fn => onSnapshot ( async ( ...args ) => {
33- await delay ( time )
34- fn ( ...args )
35- } )
36- }
37-
3830test ( 'binds refs on collections' , async ( ) => {
3931 await vm . $bind ( 'items' , collection )
4032
Original file line number Diff line number Diff line change 33 db ,
44 tick ,
55 delay ,
6+ spyUnbind ,
7+ spyOnSnapshot ,
8+ spyOnSnapshotCallback ,
69 Vue
710} from './helpers'
811
@@ -40,34 +43,6 @@ beforeEach(async () => {
4043 await delay ( 5 )
4144} )
4245
43- function spyUnbind ( ref ) {
44- const spy = jest . fn ( )
45- const onSnapshot = ref . onSnapshot . bind ( ref )
46- ref . onSnapshot = fn => {
47- const unbind = onSnapshot ( fn )
48- return ( ) => {
49- spy ( )
50- unbind ( )
51- }
52- }
53- return spy
54- }
55-
56- function spyOnSnapshot ( ref ) {
57- const onSnapshot = ref . onSnapshot . bind ( ref )
58- return ( ref . onSnapshot = jest . fn ( ( ...args ) => onSnapshot ( ...args ) ) )
59- }
60-
61- function spyOnSnapshotCallback ( ref ) {
62- const onSnapshot = ref . onSnapshot . bind ( ref )
63- const spy = jest . fn ( )
64- ref . onSnapshot = fn => onSnapshot ( ( ...args ) => {
65- spy ( )
66- fn ( ...args )
67- } )
68- return spy
69- }
70-
7146test ( 'binds refs on documents' , async ( ) => {
7247 // create an empty doc and update using the ref instead of plain data
7348 const c = collection . doc ( )
You can’t perform that action at this time.
0 commit comments