Commit c0e171f0 authored by Paul Slaughter's avatar Paul Slaughter

Update stub_component with createStubbedMethods

This is helpful at creating a stub for things like GlModal
which technically has public methods in its API
parent 34d96a71
/**
* 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>',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment