Adds a waitForMutation helper for VueX
This commit is contained in:
parent
9c3dfd2085
commit
0bc9b770e4
1 changed files with 16 additions and 2 deletions
|
@ -1,5 +1,3 @@
|
||||||
/* eslint-disable import/prefer-default-export */
|
|
||||||
|
|
||||||
const vNodeContainsText = (vnode, text) =>
|
const vNodeContainsText = (vnode, text) =>
|
||||||
(vnode.text && vnode.text.includes(text)) ||
|
(vnode.text && vnode.text.includes(text)) ||
|
||||||
(vnode.children && vnode.children.filter(child => vNodeContainsText(child, text)).length);
|
(vnode.children && vnode.children.filter(child => vNodeContainsText(child, text)).length);
|
||||||
|
@ -19,3 +17,19 @@ export const shallowWrapperContainsSlotText = (shallowWrapper, slotName, text) =
|
||||||
Boolean(
|
Boolean(
|
||||||
shallowWrapper.vm.$slots[slotName].filter(vnode => vNodeContainsText(vnode, text)).length,
|
shallowWrapper.vm.$slots[slotName].filter(vnode => vNodeContainsText(vnode, text)).length,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a promise that waits for a mutation to be fired before resolving
|
||||||
|
* NOTE: There's no reject action here so it will hang if it waits for a mutation that won't happen.
|
||||||
|
* @param {Object} store - The Vue store that contains the mutations
|
||||||
|
* @param {String} expectedMutationType - The Mutation to wait for
|
||||||
|
*/
|
||||||
|
export const waitForMutation = (store, expectedMutationType) =>
|
||||||
|
new Promise(resolve => {
|
||||||
|
const unsubscribe = store.subscribe(mutation => {
|
||||||
|
if (mutation.type === expectedMutationType) {
|
||||||
|
unsubscribe();
|
||||||
|
resolve();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
Loading…
Reference in a new issue