diff options
Diffstat (limited to 'spec/frontend/__helpers__/dl_locator_helper.js')
-rw-r--r-- | spec/frontend/__helpers__/dl_locator_helper.js | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/spec/frontend/__helpers__/dl_locator_helper.js b/spec/frontend/__helpers__/dl_locator_helper.js new file mode 100644 index 00000000000..b507dcd599d --- /dev/null +++ b/spec/frontend/__helpers__/dl_locator_helper.js @@ -0,0 +1,28 @@ +import { createWrapper, ErrorWrapper } from '@vue/test-utils'; + +/** + * Find the definition (<dd>) that corresponds to this term (<dt>) + * + * Given html in the `wrapper`: + * + * <dl> + * <dt>My label</dt> + * <dd>Value</dd> + * </dl> + * + * findDd('My label', wrapper) + * + * Returns `<dd>Value</dd>` + * + * @param {object} wrapper - Parent wrapper + * @param {string} dtLabel - Label for this value + * @returns Wrapper + */ +export const findDd = (dtLabel, wrapper) => { + const dt = wrapper.findByText(dtLabel).element; + const dd = dt.nextElementSibling; + if (dt.tagName === 'DT' && dd.tagName === 'DD') { + return createWrapper(dd, {}); + } + return ErrorWrapper(dtLabel); +}; |