Allow `@gitlab/ui` mocks to apply to internal imports

What does this MR do?

Updates the way we mock @gitlab/ui modules to allow the mocks to take effect when the modules are imported in the gitlab project and when imported internally in @gitlab/ui.

Previously, the mocks only took effect for imports in the gitlab project. This caused issues when a @gitlab/ui component internally used a problematic component/directive - the problematic component/directive wasn't mocked when running Jest tests in the gitlab project.

Now, the modules are mocked regardless of whether they are imported inside gitlab or internally inside @gitlab/ui.

Context

This update solves issues that look like this:

[BootstrapVue warn]: tooltip - Unable to find target element in document."
    found in
    ---> <BVTooltip>
           <GlClearIconButton>
             <GlSearchBoxByType>
               <BDropdown>
                 <GlDropdown>
                   <DashboardsDropdown>
                     <DashboardHeader>
                       <Anonymous>
                         <Root>

In this example, the error occurs when the @gitlab/ui component GlClearIconButton uses a GlTooltip, but the test hasn't been set up properly for tooltips (i.e. attachToDocument: true and sync: true).

The issue mentioned above began when a small change was made to GlSearchBoxByType: gitlab-ui!1550 (merged). This MR fixes these Jest issues, as can be seen in this gitlab-ui integration test MR, which includes the commit from this MR.

Edited by Nathan Friend

Merge request reports

Loading