summaryrefslogtreecommitdiff
path: root/spec/frontend/__helpers__/stub_component.js
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-01-20 09:10:52 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2021-01-20 09:10:52 +0000
commit8994750e4e1beb9f6d1b37c1625fba5868b9babf (patch)
tree57c6b4e91ceff31047a15f0be5bbdc5ef9129ef3 /spec/frontend/__helpers__/stub_component.js
parent4ca378cac72f532536a84158b3ee0da80e602151 (diff)
downloadgitlab-ce-8994750e4e1beb9f6d1b37c1625fba5868b9babf.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/__helpers__/stub_component.js')
-rw-r--r--spec/frontend/__helpers__/stub_component.js25
1 files changed, 25 insertions, 0 deletions
diff --git a/spec/frontend/__helpers__/stub_component.js b/spec/frontend/__helpers__/stub_component.js
index 45550450517..96fe3a8bc45 100644
--- a/spec/frontend/__helpers__/stub_component.js
+++ b/spec/frontend/__helpers__/stub_component.js
@@ -1,7 +1,32 @@
+/**
+ * Returns a new object with keys pointing to stubbed methods
+ *
+ * This is helpful for stubbing components like GlModal where it's supported
+ * in the API to call `.show()` and `.hide()` ([Bootstrap Vue docs][1]).
+ *
+ * [1]: https://bootstrap-vue.org/docs/components/modal#using-show-hide-and-toggle-component-methods
+ *
+ * @param {Object} methods - Object whose keys will be in the returned object.
+ */
+const createStubbedMethods = (methods = {}) => {
+ if (!methods) {
+ return {};
+ }
+
+ return Object.keys(methods).reduce(
+ (acc, key) =>
+ Object.assign(acc, {
+ [key]: () => {},
+ }),
+ {},
+ );
+};
+
export function stubComponent(Component, options = {}) {
return {
props: Component.props,
model: Component.model,
+ methods: createStubbedMethods(Component.methods),
// Do not render any slots/scoped slots except default
// This differs from VTU behavior which renders all slots
template: '<div><slot></slot></div>',