2021-01-20 04:10:52 -05:00
|
|
|
/**
|
|
|
|
* 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]: () => {},
|
|
|
|
}),
|
|
|
|
{},
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2020-12-16 13:10:10 -05:00
|
|
|
export function stubComponent(Component, options = {}) {
|
|
|
|
return {
|
|
|
|
props: Component.props,
|
|
|
|
model: Component.model,
|
2021-01-20 04:10:52 -05:00
|
|
|
methods: createStubbedMethods(Component.methods),
|
2020-12-16 13:10:10 -05:00
|
|
|
// Do not render any slots/scoped slots except default
|
|
|
|
// This differs from VTU behavior which renders all slots
|
|
|
|
template: '<div><slot></slot></div>',
|
|
|
|
// allows wrapper.find(Component) to work for stub
|
|
|
|
$_vueTestUtils_original: Component,
|
|
|
|
...options,
|
|
|
|
};
|
|
|
|
}
|