-
-
Notifications
You must be signed in to change notification settings - Fork 324
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(test): move helper functions for tests
- Loading branch information
Showing
4 changed files
with
56 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,53 @@ | ||
export * from './wait-for-update' | ||
import Vue from 'vue' | ||
|
||
Vue.config.productionTip = false | ||
export { Vue } | ||
|
||
export * from './mock' | ||
|
||
export function spyUnbind (ref) { | ||
const spy = jest.fn() | ||
const onSnapshot = ref.onSnapshot.bind(ref) | ||
ref.onSnapshot = fn => { | ||
const unbind = onSnapshot(fn) | ||
return () => { | ||
spy() | ||
unbind() | ||
} | ||
} | ||
return spy | ||
} | ||
|
||
export function spyOnSnapshot (ref) { | ||
const onSnapshot = ref.onSnapshot.bind(ref) | ||
return (ref.onSnapshot = jest.fn((...args) => onSnapshot(...args))) | ||
} | ||
|
||
export function spyOnSnapshotCallback (ref) { | ||
const onSnapshot = ref.onSnapshot.bind(ref) | ||
const spy = jest.fn() | ||
ref.onSnapshot = fn => onSnapshot((...args) => { | ||
spy() | ||
fn(...args) | ||
}) | ||
return spy | ||
} | ||
|
||
// This makes sure some tests fail by delaying callbacks | ||
export function delayUpdate (ref, time = 0) { | ||
const onSnapshot = ref.onSnapshot.bind(ref) | ||
ref.onSnapshot = fn => onSnapshot(async (...args) => { | ||
await delay(time) | ||
fn(...args) | ||
}) | ||
} | ||
|
||
export function tick () { | ||
return new Promise((resolve, reject) => { | ||
Vue.nextTick(resolve) | ||
}) | ||
} | ||
|
||
export function delay (time) { | ||
return new Promise(resolve => setTimeout(resolve, time)) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters