diff options
author | Fatih Acet <acetfatih@gmail.com> | 2019-07-22 12:31:28 +0000 |
---|---|---|
committer | Fatih Acet <acetfatih@gmail.com> | 2019-07-22 12:31:28 +0000 |
commit | 8204a876ee098191b4be5aa1955c76277cddb3a8 (patch) | |
tree | 796f3d7b4e8d3bf364272280d4c14cee99cd5f2c | |
parent | 886a6957ec0d981426219f42d75e0af145a9f7cf (diff) | |
parent | 0bc9b770e459f3e573be70a21221361dea2d9fa8 (diff) | |
download | gitlab-ce-8204a876ee098191b4be5aa1955c76277cddb3a8.tar.gz |
Merge branch '11975-move-SAST-to-the-frontend-ce' into 'master'
Adds a waitForMutation helper for VueX(CE backport)
See merge request gitlab-org/gitlab-ce!30186
-rw-r--r-- | spec/javascripts/helpers/vue_test_utils_helper.js | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/spec/javascripts/helpers/vue_test_utils_helper.js b/spec/javascripts/helpers/vue_test_utils_helper.js index 121e99c9783..68326e37ae7 100644 --- a/spec/javascripts/helpers/vue_test_utils_helper.js +++ b/spec/javascripts/helpers/vue_test_utils_helper.js @@ -1,5 +1,3 @@ -/* eslint-disable import/prefer-default-export */ - const vNodeContainsText = (vnode, text) => (vnode.text && vnode.text.includes(text)) || (vnode.children && vnode.children.filter(child => vNodeContainsText(child, text)).length); @@ -19,3 +17,19 @@ export const shallowWrapperContainsSlotText = (shallowWrapper, slotName, text) = Boolean( 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(); + } + }); + }); |