gitlab-org--gitlab-foss/spec/javascripts/helpers/vue_test_utils_helper.js
Nathan Friend bee3c7e847 Comply with no-implicit-coercion rule (CE)
This commit is the result of running `yarn eslint --fix` after enabling
the `no-implicit-coercion` ESLint rule.  This rule has been added to
our ESLint config here:

https://gitlab.com/gitlab-org/gitlab-eslint-config/merge_requests/14
2019-06-03 22:51:02 +00:00

21 lines
889 B
JavaScript

/* 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);
/**
* Determines whether a `shallowMount` Wrapper contains text
* within one of it's slots. This will also work on Wrappers
* acquired with `find()`, but only if it's parent Wrapper
* was shallowMounted.
* NOTE: Prefer checking the rendered output of a component
* wherever possible using something like `text()` instead.
* @param {Wrapper} shallowWrapper - Vue test utils wrapper (shallowMounted)
* @param {String} slotName
* @param {String} text
*/
export const shallowWrapperContainsSlotText = (shallowWrapper, slotName, text) =>
Boolean(
shallowWrapper.vm.$slots[slotName].filter(vnode => vNodeContainsText(vnode, text)).length,
);